Skip to content

Commit

Permalink
feat: Add gatekeeper policy (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
samirtahir91 committed Jul 13, 2024
1 parent bcd44f9 commit 6a7b766
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The `github-app-operator` is a Kubernetes operator that generates an access toke
- Stores the access token in a secret specified by `accessTokenSecret`.

### Private Key Retrieval Options
> [!TIP]
> There is a sample constraint template and constraint for Gatekeeper to restrict the type of private key source in the `gatekeeper-policy` folder since we can't restrict it to be unique in the GithubApp CRD.

#### 1. Using a Kubernetes Secret
- **Configuration:**
Expand Down
22 changes: 22 additions & 0 deletions gatekeeper-policy/constraint-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
name: githubappprivatekey
spec:
crd:
spec:
names:
kind: GithubAppPrivateKey
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package githubappsecrets
violation[{"msg": msg}] {
target_keys := {"privateKeySecret", "googlePrivateKeySecret", "vaultPrivateKey"}
provided_keys := {key | _ = input.review.object.spec[key]}
intersection := target_keys & provided_keys
count(intersection) != 1
invalid := provided_keys - target_keys
msg := "Exactly one of privateKeySecret, googlePrivateKeySecret or vaultPrivateKey are allowed"
}
9 changes: 9 additions & 0 deletions gatekeeper-policy/constraint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: GithubAppPrivateKey
metadata:
name: githubapp-unique-key-constraint
spec:
match:
kinds:
- apiGroups: ["githubapp.samir.io"]
kinds: ["GithubApp"]

0 comments on commit 6a7b766

Please sign in to comment.