Skip to content

Commit

Permalink
install a default service account
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright committed Oct 10, 2024
1 parent 8e705a5 commit 5531fd4
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 40 deletions.
2 changes: 2 additions & 0 deletions operator/config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ resources:
- ../crd
- ../rbac
- ../manager
- ./service_account.yaml
- ./rbac.yaml
14 changes: 14 additions & 0 deletions operator/config/default/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Grant `system:auth-delegator` to the `default/pulumi` service account,
# to enable Kubernetes RBAC for the Pulumi workspace.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: default:pulumi:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator # permissions: TokenReview, SubjectAccessReview
subjects:
- kind: ServiceAccount
namespace: default
name: pulumi
8 changes: 8 additions & 0 deletions operator/config/default/service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# A service account named `default/pulumi` for the Pulumi workspace (execution environment).
# If your Pulumi program uses the Kubernetes resource provider, this service account will be used to
# authenticate with the Kubernetes cluster.
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: default
name: pulumi
26 changes: 26 additions & 0 deletions operator/config/flux/network_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# A network policy to allow Pulumi workspaces in the `default` namespace to
# fetch Flux artifacts from the source-controller in the `flux-system` namespace.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-pulumi-fetch-flux-artifacts
namespace: flux-system
spec:
podSelector:
matchLabels:
app: source-controller
ingress:
- ports:
- protocol: TCP
port: http
from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: default
- podSelector:
matchLabels:
app.kubernetes.io/managed-by: pulumi-kubernetes-operator
app.kubernetes.io/name: pulumi
app.kubernetes.io/component: workspace
policyTypes:
- Ingress
39 changes: 19 additions & 20 deletions operator/e2e/testdata/git-auth-nonroot/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ metadata:
name: git-auth-nonroot
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: git-auth-nonroot
namespace: git-auth-nonroot
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: git-auth-nonroot:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: git-auth-nonroot
namespace: git-auth-nonroot
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: state
Expand All @@ -24,26 +43,6 @@ metadata:
stringData:
accessToken: $PULUMI_BOT_TOKEN
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: git-auth-nonroot
namespace: git-auth-nonroot
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: git-auth-nonroot:system:auth-delegator
namespace: git-auth-nonroot
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: git-auth-nonroot
namespace: git-auth-nonroot
---
apiVersion: pulumi.com/v1
kind: Stack
metadata:
Expand Down
42 changes: 22 additions & 20 deletions operator/e2e/testdata/random-yaml-nonroot/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
Expand All @@ -17,6 +18,8 @@ spec:
kubernetes.io/metadata.name: random-yaml-nonroot
- podSelector:
matchLabels:
app.kubernetes.io/managed-by: pulumi-kubernetes-operator
app.kubernetes.io/name: pulumi
app.kubernetes.io/component: workspace
policyTypes:
- Ingress
Expand All @@ -27,6 +30,25 @@ metadata:
name: random-yaml-nonroot
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: random-yaml-nonroot
namespace: random-yaml-nonroot
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: random-yaml-nonroot:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: random-yaml-nonroot
namespace: random-yaml-nonroot
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: state
Expand All @@ -50,26 +72,6 @@ spec:
timeout: 60s
url: https://github.com/pulumi/examples
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: random-yaml-nonroot
namespace: random-yaml-nonroot
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: random-yaml-nonroot:system:auth-delegator
namespace: random-yaml-nonroot
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: random-yaml-nonroot
namespace: random-yaml-nonroot
---
apiVersion: pulumi.com/v1
kind: Stack
metadata:
Expand Down
21 changes: 21 additions & 0 deletions operator/examples/random-yaml/stack.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: random-yaml
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: random-yaml:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: random-yaml
namespace: default
---
apiVersion: pulumi.com/v1
kind: Stack
metadata:
name: random-yaml
namespace: default
spec:
fluxSource:
sourceRef:
Expand All @@ -24,5 +44,6 @@ spec:
key: accessToken
workspaceTemplate:
spec:
serviceAccountName: random-yaml
image: pulumi/pulumi:3.134.1-nonroot

0 comments on commit 5531fd4

Please sign in to comment.