Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add gatekeeper policy #67

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
Loading