shieldworks / aegis

Aegis: Keep Your Secrets… Secret
https://vsecm.com
MIT License
31 stars 3 forks source link

Controller to reject aegis-managed SVIDs that don't conform a certain template. #88

Open v0lkan opened 1 year ago

v0lkan commented 1 year ago

A typical Aegis workload SVID is in the following form:

apiVersion: spire.spiffe.io/v1alpha1
kind: ClusterSPIFFEID
metadata:
  name: aegis-workload-demo
spec:
  spiffeIDTemplate: "spiffe://aegis.z2h.dev/workload/aegis-workload-demo/ns/{{ .PodMeta.Namespace }}/sa/{{ .PodSpec.ServiceAccountName }}/n/{{ .PodMeta.Name }}"
  podSelector:
    matchLabels:
      app.kubernetes.io/name: aegis-workload-demo
  workloadSelectorTemplates:
  - "k8s:ns:{{ .PodMeta.Namespace }}"
  - "k8s:sa:{{ .PodSpec.ServiceAccountName }}

However, as of now, there is nothing preventing and administrator from interpolating the meta information themselves and coming up with an ID like:

apiVersion: spire.spiffe.io/v1alpha1
kind: ClusterSPIFFEID
metadata:
  name: aegis-workload-demo
spec:
  spiffeIDTemplate: "spiffe://aegis.z2h.dev/workload/aegis-workload-demo/ns/someone-elses-namespace/sa/someone-elses-service/n/some-other-pods-name"
  podSelector:
    matchLabels:
      app.kubernetes.io/name: aegis-workload-demo
# workloadSelectorTemplates:
# no workload selector templates at all.

Although you still need sufficient admin privileges to do this; it is better to safeguard against that.

Acceptance Criteria

v0lkan commented 1 year ago

Note that this Controller is a “nice to have”, but not mandatory.

ClusterSpiffeIDs shall be only created by the authorized admins in the first place.

The controller can periodically check and rectify any misconfigurations and/or delete ClusterSPIFFEIDs that do not conform a standard.

v0lkan commented 1 year ago

Note that instead of a custom operator, we can use an admission webhook as a gatekeeper:

https://kubernetes.io/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/

v0lkan commented 1 year ago

Punting to 1.1.0 as this is important, yet less urgent.

v0lkan commented 1 year ago

This can be a starting point for other controller-related tasks.

v0lkan commented 1 year ago

Counter point: This is not about security; since an administrator can very-well disable the controller too. It is more about “convenience”.

And for convenience, instead of running yet another process all the time inside the cluster, maybe an offline schema validator would be more useful.

A validator that

There are several tools that can be used to facilitate such an offline validation:

We can pick one that fits best to our needs, and create a validator app that you can run before each deployment.