Commit Graph

30 Commits

Author SHA1 Message Date
Jeff McCune
4c5429b64a (#22) Ceph CSI for Metal clusters
This patch adds the ceph-csi-rbd helm chart component to the metal
cluster type.  The purpose is to enable PersistentVolumeClaims on ois
metal clusters.

Cloud clusters like GKE and EKS are expected to skip rendering the metal
type.

Helm values are handled with CUE.  The ceph secret is managed as an
ExternalSecret resource, appended to the rendered output by cue and the
holos cli.

Use:

    ❯ holos render --cluster-name=k2 ~/workspace/holos-run/holos/docs/examples/platforms/reference/clusters/metal/...
    2:45PM INF render.go:40 rendered prod-metal-ceph version=0.47.0 status=ok action=rendered name=prod-metal-ceph
2024-02-28 14:46:03 -08:00
Jeff McCune
6090ab224e (#14) Validate secrets fetched from provisioner cluster
This patch validates secrets are synced from the provisioner cluster to
a workload cluster.  This verifies the eso-creds-refresher job, external
secrets operator, etc...

Refer to
0ae58858f5
for the corresponding commit on the k2 cluster.
2024-02-27 15:55:17 -08:00
Jeff McCune
10e140258d (#15) Report multiple cue errors
This patch prints out the cue file and line numbers when a cue error
contains multiple go errors to unwrap.

For example:

```
❯ holos render --cluster-name=k2 ~/workspace/holos-run/holos/docs/examples/platforms/reference/clusters/workload/...
3:31PM ERR could not execute version=0.46.0 err="could not decode: content: error in call to encoding/yaml.MarshalStream: incomplete value string (and 1 more errors)" loc=builder.go:212
content: error in call to encoding/yaml.MarshalStream: incomplete value string:
    /home/jeff/workspace/holos-run/holos/docs/examples/schema.cue:199:11
    /home/jeff/workspace/holos-run/holos/docs/examples/cue.mod/gen/external-secrets.io/externalsecret/v1beta1/types_gen.cue:83:14
```
2024-02-27 15:32:11 -08:00
Jeff McCune
b4ad6425e5 (#14) Validate SecretStore works
This patch validates a SecretStore in the holos-system namespace works
after provisioner credentials are refreshed.
2024-02-27 11:25:00 -08:00
Jeff McCune
3343d226e5 (#14) Fix namespaces "external-secrets" not found
Needed for the `prod-secrets-eso` component to reconcile with flux.

NAME                                    REVISION                SUSPENDED       READY   MESSAGE
flux-system                             main@sha1:28b9ab6b      False           True    Applied revision: main@sha1:28b9ab6b
prod-secrets-eso                        main@sha1:28b9ab6b      False           True    Applied revision: main@sha1:28b9ab6b
prod-secrets-eso-creds-refresher        main@sha1:28b9ab6b      False           True    Applied revision: main@sha1:28b9ab6b
prod-secrets-namespaces                 main@sha1:28b9ab6b      False           True    Applied revision: main@sha1:28b9ab6b
2024-02-26 20:53:43 -08:00
Jeff McCune
51f22443f3 Move secrets project components to the workload cluster
Goal is to render all of the flux kustomization components with:

```
❯ holos render --cluster-name=k2 ~/workspace/holos-run/holos/docs/examples/platforms/reference/clusters/workload/...
4:47PM INF render.go:39 rendered prod-secrets-eso version=0.42.1 status=ok action=rendered name=prod-secrets-eso
4:47PM INF render.go:39 rendered prod-secrets-eso-creds-refresher version=0.42.1 status=ok action=rendered name=prod-secrets-eso-creds-refresher
4:47PM INF render.go:39 rendered prod-secrets-namespaces version=0.42.1 status=ok action=rendered name=prod-secrets-namespaces
```
2024-02-21 16:45:48 -08:00
Jeff McCune
e98ee28f74 Add eso-creds-refresher CronJob
This patch adds the `eso-creds-refresher` CronJob which executes every 8
hours in the holos-system namespace of each workload cluster.  The job
creates Secrets with a `token` field representing the id token
credential for a SecretStore to use when synchronizing secrets to and
from the provisioner cluster.

Service accounts in the provisioner cluster are selected with
selector=holos.run/job.name=eso-creds-refresher.

Each selected service account has a token issued with a 12 hour
expiration ttl and is stored in a Secret matching the service account
name in the same namespace in the workload cluster.

The job takes about 25 seconds to run once the image is cached on the
node.
2024-02-21 15:09:26 -08:00
Jeff McCune
b16d3459f7 Allow eso-creds-refresher iam service account to list ksas
Without this patch the Job on a workload cluster fails with:

```
+ kubectl get serviceaccount -A --selector=holos.run/job.name=eso-creds-refresher --output=json
Error from server (Forbidden): serviceaccounts is forbidden: User
"eso-creds-refresher@holos-run.iam.gserviceaccount.com" cannot list
resource "serviceaccounts" in API group "" at the cluster scope:
requires one of ["container.serviceAccounts.list"] permission(s).
```
2024-02-21 11:13:04 -08:00
Jeff McCune
f41b883dce Add holos.run/job.name=eso-creds-refresher label to ksa
This label is intended for the Job to select which service accounts to
issue tokens for.  For example:

  kubectl get serviceaccount -A --selector=holos.run/job.name=eso-creds-refresher --output=json
2024-02-21 11:03:33 -08:00
Jeff McCune
572281914c Remove view role from eso-creds-refresher
Listing namespaces is sufficient, viewing all resources isn't necessary.
2024-02-21 10:32:41 -08:00
Jeff McCune
4cdf9d2dae Refactor eso-reader and eso-writer provisioner service accounts
Without this patch it is difficult to navigate the structure of the
configuration of the api objects because they're positional elements in
a list.

This patch extracts the configuration of the eso-reader and eso-writer
ServiceAccount, Role, and RoleBinding structs into a definition that
behaves like a function.  The individual objects are fields of the
struct instead of positional elements in a list.
2024-02-21 10:08:39 -08:00
Jeff McCune
fd306aae76 Pod eso-creds-refresher authenticates to provisioner
This patch adds a ConfigMap and Pod to the eso-creds-refresher
component.  The Pod executes the gcloud container, impersonates the
eso-creds-refresher iam service account using workload identity, then
authenticates to the remote provisioner cluster.

This is the foundation for a script to automatically create Secret API
objects in a workload cluster which have a kubernetes service account
token ESO SecretStore resources can use to fetch secrets from the
provisioner cluster.

Once we have that script in place we can turn this Pod into a Job and
replace Vault.
2024-02-20 17:45:43 -08:00
Jeff McCune
5bf2b85036 Refactor namespaces separate from eso-creds-refresher
Manage namespaces in a separate component so we can easily run the
eso-creds-refresher component through kubectl delete -f- without
deleting the namespace.

For the k2 cluster:

```
❯ holos build ./platforms/reference/clusters/workload/... | k apply --server-side=true -f-
serviceaccount/eso-creds-refresher serverside-applied
clusterrole.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
clusterrolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
namespace/holos-system serverside-applied
namespace/flux-system serverside-applied
namespace/ceph-system serverside-applied
namespace/istio-system serverside-applied
namespace/istio-ingress serverside-applied
namespace/cert-manager serverside-applied
namespace/argocd serverside-applied
```

For the provisioner cluster:

```
❯ holos build ./platforms/reference/clusters/provisioner/... | k apply --server-side=true -f-
clusterrolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-creds-refresher serverside-applied
serviceaccount/eso-reader serverside-applied
role.rbac.authorization.k8s.io/eso-reader serverside-applied
rolebinding.rbac.authorization.k8s.io/eso-reader serverside-applied
serviceaccount/eso-writer serverside-applied
role.rbac.authorization.k8s.io/eso-writer serverside-applied
namespace/holos-system serverside-applied
namespace/flux-system serverside-applied
namespace/ceph-system serverside-applied
namespace/istio-system serverside-applied
namespace/istio-ingress serverside-applied
namespace/cert-manager serverside-applied
namespace/argocd serverside-applied
```
2024-02-20 15:40:32 -08:00
Jeff McCune
0771bd6b6c Configure namespaces in the provisioner cluster
The provisioner cluster is a worker-less autopilot cluster that provides
secrets to other clusters in the platform.  The `eso-creds-refresher`
Job in the holos-system namespace of each other cluster refreshes
service account tokens for SecretStores.

This patch adds the IAM structure for the Job implemented by Namespace,
ServiceAccount, Role, and RoleBinding api objects.
2024-02-19 21:37:13 -08:00
Jeff McCune
f647a4a76c Fix secret validation path 2024-02-13 17:58:21 -08:00
Jeff McCune
37d5eac841 Add dependency from prod-secrets-validate to prod-secrets-eso 2024-02-13 17:44:21 -08:00
Jeff McCune
a6dab235f5 Add SecretStore and ExternalSecret validation component
This patch adds a holos component to deploy a SecretStore and
ExternalSecret in the default namespace to validate authentication with
Vault is configured correctly.

The default ksa is used to authenticate to vault.
2024-02-13 17:21:14 -08:00
Jeff McCune
f4c85736a2 Move instances to leaf nodes for cue
This patch makes it possible to build all components for a platform with
a single command:

  ❯ holos render ~/workspace/holos-run/holos/docs/examples/platforms/reference/...
  2:51PM INF render.go:39 rendered prod-secrets-eso version=0.42.0 status=ok action=rendered name=prod-secrets-eso
  2:51PM INF render.go:39 rendered prod-secrets-namespaces version=0.42.0 status=ok action=rendered name=prod-secrets-namespaces

Note the `reference/...` path base name.  Without this patch cue tried
to build an intermediate directory instance.
2024-02-13 14:51:01 -08:00
Jeff McCune
f9fef06c55 Cache helm charts
This patch speeds up rendering by storing a copy of helm charts in the
holos component directory.
2024-02-13 14:24:45 -08:00
Jeff McCune
039fb056c0 Have prod-secrets-eso depend on prod-secrets-namespaces
This patch is an example of using CUE to add the dependsOn field to the
generated kustomization.yaml.

```
❯ holos render ~/workspace/holos-run/holos/docs/examples/platforms/reference/projects/secrets/components/...
11:51AM INF render.go:39 rendered prod-secrets-eso version=0.41.0 status=ok action=rendered name=prod-secrets-eso
11:51AM INF render.go:39 rendered prod-secrets-namespaces version=0.41.0 status=ok action=rendered name=prod-secrets-namespaces

❯ git add -p
diff --git a/deploy/clusters/k2/holos/components/prod-secrets-eso-kustomization.gen.yaml b/deploy/clusters/k2/holos/components/prod-secrets-eso-kustomization.gen.yaml
index 74c626d0..2dedf991 100644
--- a/deploy/clusters/k2/holos/components/prod-secrets-eso-kustomization.gen.yaml
+++ b/deploy/clusters/k2/holos/components/prod-secrets-eso-kustomization.gen.yaml
@@ -4,6 +4,8 @@ metadata:
   name: prod-secrets-eso
   namespace: flux-system
 spec:
+  dependsOn:
+    - name: prod-secrets-namespaces
   interval: 30m0s
   path: deploy/clusters/k2/components/prod-secrets-eso
   prune: true
```
2024-02-13 11:51:55 -08:00
Jeff McCune
cde4380049 Add holos component HelmChart type
This patch implements rendering a holos component from an upstream helm
chart using a values.yaml file generated by CUE.  The resulting
kubernetes api objects are saved to the deploy directory in the same way
the KubernetesObject holos component type.

```
❯ holos render --cluster-name=core2 ./docs/examples/platforms/reference/projects/secrets/components/...
3:55PM INF render.go:39 rendered prod-secrets-eso version=0.41.0 status=ok action=rendered name=prod-secrets-eso
3:55PM INF render.go:39 rendered prod-secrets-namespaces version=0.41.0 status=ok action=rendered name=prod-secrets-namespaces
```

```
❯ tree deploy
deploy
└── clusters
    └── core2
        ├── components
        │   ├── prod-secrets-eso
        │   │   └── prod-secrets-eso.gen.yaml
        │   └── prod-secrets-namespaces
        │       └── prod-secrets-namespaces.gen.yaml
        └── holos
            └── components
                ├── prod-secrets-eso-kustomization.gen.yaml
                └── prod-secrets-namespaces-kustomization.gen.yaml

7 directories, 4 files
```
2024-02-12 15:56:06 -08:00
Jeff McCune
0d4f36333f Add platform and instance values to helm values 2024-02-12 10:16:40 -08:00
Jeff McCune
69916a13ab Decode cue values for use as helm values
In helm mode, cue is responsible for producing the values.yaml file.
Holos is responsible for taking the values produced by cue and providing
them to helm to produce rendered kubernetes api objects.

This patch adds intermediate data structures to hold the output from
cue: the helm values, the flux kustomization, and the helm charts to
provide the helm values to.

Holos takes this information and orchestrates running helm template to
render the api objects and write them to the file system for git ops.
2024-02-12 09:53:47 -08:00
Jeff McCune
9739fc6471 Initial structure for helm support
Stopping here to look into generating go types from the cue output type
definitions.
2024-02-10 17:14:42 -08:00
Jeff McCune
bb06fa742a Render flux Kustomization along with api objects
This patch writes a Flux Kustomization to apply the api objects rendered
by a component instance.

    ❯ holos render --log-format=json --log-level=debug --cluster-name core2 ./docs/examples/platforms/reference/projects/secrets/components/namespaces/ 2> >(./scripts/msgs)
    config.go:91    finalized config from flags
    builder.go:129  cue export --out yaml -t cluster=core2 ./platforms/reference/projects/secrets/components/namespaces
    builder.go:134  configured cue tags: [cluster=core2]
    builder.go:94   wrote deploy/clusters/core2/components/prod-secrets-namespaces/prod-secrets-namespaces.gen.yaml
    builder.go:94   wrote deploy/clusters/core2/holos/components/prod-secrets-namespaces-kustomization.gen.yaml
    render.go:39    rendered prod-secrets-namespaces

```yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: prod-secrets-namespaces
  namespace: flux-system
spec:
  interval: 30m0s
  path: deploy/clusters/core2/components/prod-secrets-namespaces
  prune: true
  retryInterval: 2m0s
  sourceRef:
    kind: GitRepository
    name: flux-system
  timeout: 3m0s
  wait: true
```
2024-02-09 15:42:50 -08:00
Jeff McCune
7dce445c1a Import flux v2.2.3 crds into cue schemas
timoni mod vendor crds -f https://github.com/fluxcd/flux2/releases/download/v2.2.3/install.yaml
2024-02-09 13:45:57 -08:00
Jeff McCune
e2b1fa0d47 Rename cue out field to content and add content-type
Content seems more appropriate of a field name, and it makes sense since
we are likely to output other formats than yaml, probably json too.  We
need to discriminate on content type, so also add a contentType field.

Semantics are meant to be the same has the http content type header, but
simple.
2024-02-08 22:26:07 -08:00
Jeff McCune
e018deef5a Add name field to cue output schema
The intent is for all of the output formats to share a common `name`
field, useful to construct a file name to write rendered output to for
git ops.

This is equivalent to the OrderedComponent name specified in the
platform.yaml in the prototype.
2024-02-08 22:09:00 -08:00
Jeff McCune
9bebd2e4b6 Discriminate on cue export type
Leaf directories can output different kinds of things:

 1. Platform specification.  A list of components to manage.
 2. Kubernetes API Objects suitable for kubectl apply -f- and friends.
 3. Helm values to provide to a helm chart to render API objects.

This patch adds an output schema and a kind discriminator so the holos
cli can figure out what type of output it's working with.  This makes it
possible to have a single `holos build <directory>` command that does
the right thing.
2024-02-06 15:47:13 -08:00
Jeff McCune
9603e6b551 Manage the external-secrets namespace
This patch adds the first platform component built with CUE.  The intent
is to give a concrete use case for migrating the platform.yaml spec over
to the new approach with CUE.

This component is a simple namespace for the external secrets operator.
The majority of this patch is in setting up the structure of the CUE
module.  The component is _not_ wired up to the holos cli yet, instead
it's built directly with cue using:

    cd ./docs/examples/
    cue export --out text -t cluster=core1 -e out ./platforms/reference/projects/secrets/components/namespaces/...

The command produces the same output as the was previously produced
using helm templates [here][1].

[1]: https://github.com/holos-run/holos-infra/blob/v0.4.0/deploy/clusters/core1/components/prod-secrets-namespaces/prod-secrets-namespaces.nofmt.yaml
2024-02-05 14:07:56 -08:00