Skip to content

Instantly share code, notes, and snippets.

@ddgenome
Created January 15, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddgenome/159f6c30f5d252e4ebd56c6067b9a604 to your computer and use it in GitHub Desktop.
Save ddgenome/159f6c30f5d252e4ebd56c6067b9a604 to your computer and use it in GitHub Desktop.
Kubernetes RBAC role, service account, and role binding for no access to in-cluster Kubernetes API
import * as k8s from "@kubernetes/client-node";
import { DeepPartial } from "ts-essentials";
const serviceAccount: DeepPartial<k8s.V1ServiceAccount> = {
apiVersion: "v1",
kind: "ServiceAccount",
metadata: {
name: "noaccess",
},
};
const role: DeepPartial<k8s.V1Role> = {
apiVersion: "rbac.authorization.k8s.io/v1beta1",
kind: "Role",
metadata: {
name: "noaccess",
},
rules: [],
};
const roleBinding: DeepPartial<k8s.V1RoleBinding> = {
apiVersion: "rbac.authorization.k8s.io/v1beta1",
kind: "RoleBinding",
metadata: {
name: "noaccess",
},
roleRef: {
apiGroup: "rbac.authorization.k8s.io",
kind: "Role",
name: "noaccess",
},
subjects: [
{
kind: "ServiceAccount",
name: "noaccess",
},
],
};
@cdupuis
Copy link

cdupuis commented Jan 16, 2019

Thanks @ddgenome. I assume I have to apply top down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment