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

Add support for AdditionalTrustBundle #972

Merged
merged 8 commits into from Mar 28, 2022

Conversation

hardys
Copy link
Contributor

@hardys hardys commented Feb 4, 2022

This adds initial support for a new HostedCluster API additionalTrustBundle which allows user provided CA certs to be provided, similar to the standalone installer

This is useful when you want to use a local container registry that uses a self-signed cert - this is a common scenario for developing on-prem scenarios, particularly disconnected and ipv6 where access to an upstream registry is not possible.

The expected usage is to reference a local object reference, e.g ConfigMap in the clusters namespace:

spec:
  additionalTrustBundle:
    name: user-ca-bundle

If the management cluster already contains such a ConfigMap, it may be copied from the openshift-config namespace, e.g:

oc patch cm user-ca-bundle -p '{"metadata":{ "namespace":"clusters"}}' -n openshift-config --dry-run=client -o yaml | oc apply -f -

Partially-Fixes https://issues.redhat.com/browse/HOSTEDCP-291

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

@hardys hardys requested a review from csrwng February 4, 2022 17:43
@netlify
Copy link

netlify bot commented Feb 4, 2022

✔️ Deploy Preview for hypershift-docs ready!

🔨 Explore the source changes: cbd329c

🔍 Inspect the deploy log: https://app.netlify.com/sites/hypershift-docs/deploys/62349e17297c970009572250

😎 Browse the preview: https://deploy-preview-972--hypershift-docs.netlify.app/reference/api

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 4, 2022
@hardys
Copy link
Contributor Author

hardys commented Feb 4, 2022

/cc @csrwng @enxebre

This implements the changes described in HOSTEDCP-291 - I went with the local object reference option, since it seems more convenient (particularly in the case where you want to copy the ConfigMap from the management cluster) than inlining the cert contents.

Left as WIP because:

  • I've not yet tested the MCS part, or e2e with a local registry
  • I need to add some unit tests
  • It doesn't yet handle the delete path (when AdditionalTrustBundle is removed from HostedCluster/HostedControlPlane, although this seems a fairly unlikely corner-case)
  • I suspect we need to wire the user CA into some hosted controlplane pods

I'm also not sure if we need to replicate any of the CNO ConfigMapInjector logic - since we do see several CMs with that label in the guest cluster:

$ oc get cm --selector=config.openshift.io/inject-trusted-cabundle=true -A
NAMESPACE                                NAME                DATA   AGE
openshift-apiserver-operator             trusted-ca-bundle   0      5h39m
openshift-authentication-operator        trusted-ca-bundle   0      5h39m
openshift-cloud-credential-operator      cco-trusted-ca      0      5h39m
openshift-cluster-node-tuning-operator   trusted-ca          0      5h39m
openshift-image-registry                 trusted-ca          0      5h39m
openshift-ingress-operator               trusted-ca          0      5h39m
openshift-insights                       trusted-ca-bundle   0      5h39m
openshift-machine-api                    cbo-trusted-ca      0      5h40m
openshift-machine-api                    mao-trusted-ca      0      5h40m

Any thoughts on that, and review of the changes so far would be welcome, thanks!

@openshift-ci openshift-ci bot requested a review from enxebre February 4, 2022 18:00
@sjenning
Copy link
Contributor

sjenning commented Feb 4, 2022

untracked files detected: M hack/app-sre/saas_template.yaml

API changes require make verify to update generated files. This isn't the best. I opened a PR for an update make target #976.

@hardys
Copy link
Contributor Author

hardys commented Mar 4, 2022

This is closer, the hypershift operator can now start consuming a release image from a local self-signed mirror, but I need to also wire in the trusted-ca-bundle to the CPO

@hardys hardys force-pushed the additional_trust_bundle branch 2 times, most recently from 8db40d6 to 050eb1f Compare March 14, 2022 16:44
@hardys
Copy link
Contributor Author

hardys commented Mar 14, 2022

This is now working - tested with this dev-scripts branch (None platform)

Hypershift was installed using a local release image, now that the user CA is wired into the pods that use the registryclient all pods start up OK

hypershift install --hypershift-image virthost.ostest.test.metalkube.org:5000/hypershift:latest --additional-trust-bundle user-ca-bundle

The cluster was then deployed like:

hypershift create cluster none --etcd-storage-class local-storage --ssh-key /home/shardy/.ssh/id_rsa.pub --name shtest --node-pool-replicas 2 --render --additional-trust-bundle user-ca-bundle --control-plane-operator-image virthost.ostest.test.metalkube.org:5000/hypershift:latest --release-image virthost.ostest.test.metalkube.org:5000/localimages/local-release-image:latest --pull-secret /home/shardy/dev-scripts/ocp/ostest/hypershift/pull_secret.json

Note --render was used to enable addition of the ICSP config as follows (in future adding a CLI option for this would be nice):

  imageContentSources:
  - mirrors:
    - virthost.ostest.test.metalkube.org:5000/localimages/local-release-image
    source: registry.ci.openshift.org/ocp/release
  - mirrors:
    - virthost.ostest.test.metalkube.org:5000/localimages/local-release-image
    source: registry.ci.openshift.org/ocp/4.11-2022-03-04-042425

This results in a working cluster, with the expected ICSP and two nodes were joined and pulled their images correctly from the mirror:

$ oc get imageContentSourcePolicy -o yaml
apiVersion: v1
items:
- apiVersion: operator.openshift.io/v1alpha1
  kind: ImageContentSourcePolicy
  metadata:
    creationTimestamp: "2022-03-14T16:26:07Z"
    generation: 1
    labels:
      hypershift.io/managed: "true"
      machineconfiguration.openshift.io/role: worker
    name: cluster
    resourceVersion: "1037"
    uid: c12eeccd-0d07-4686-bcfb-c0254d563632
  spec:
    repositoryDigestMirrors:
    - mirrors:
      - virthost.ostest.test.metalkube.org:5000/localimages/local-release-image
      source: registry.ci.openshift.org/ocp/release
    - mirrors:
      - virthost.ostest.test.metalkube.org:5000/localimages/local-release-image
      source: registry.ci.openshift.org/ocp/4.11-2022-03-04-042425
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

$ oc version
Client Version: 4.11.0-0.ci-2022-03-04-042425
Server Version: 4.11.0-0.ci-2022-03-04-042425
Kubernetes Version: v1.23.3-2001+7478cf2c86c567-dirty

$ oc get nodes
NAME                 STATUS   ROLES    AGE     VERSION
hypershiftworker-0   Ready    worker   9m18s   v1.23.3+7478cf2
hypershiftworker-1   Ready    worker   9m18s   v1.23.3+7478cf2

This still needs some tests/docs but otherwise ready for review :)

@hardys
Copy link
Contributor Author

hardys commented Mar 15, 2022

/retitle Add support for AdditionalTrustBundle

@openshift-ci openshift-ci bot changed the title [WIP] Add support for AdditionalTrustBundle Add support for AdditionalTrustBundle Mar 15, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 15, 2022
Copy link
Contributor

@csrwng csrwng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hardys thank you so much for working on this. It looks good to me. Just a couple of nits.

cmd/cluster/cluster.go Outdated Show resolved Hide resolved
@hardys
Copy link
Contributor Author

hardys commented Mar 16, 2022

/hold the CI failures are real

{"level":"error","ts":"2022-03-15T16:54:22Z","logger":"controller.hostedcluster","msg":"Reconciler error","reconciler group":"hypershift.openshift.io","reconciler kind":"HostedCluster","name":"example-lswql","namespace":"e2e-clusters-jqm87","error":"failed to get hostedcluster AdditionalTrustBundle ConfigMap : ConfigMap \"\" not found","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/hypershift/vendor/sigs.k8s.io

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 16, 2022
@hardys hardys force-pushed the additional_trust_bundle branch 3 times, most recently from cbd329c to 0801be1 Compare March 18, 2022 15:28
@hardys
Copy link
Contributor Author

hardys commented Mar 24, 2022

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 24, 2022
@hardys
Copy link
Contributor Author

hardys commented Mar 24, 2022

@csrwng this is ready for another review pass when you get some time, thanks!

Steven Hardy added 4 commits March 25, 2022 11:36
HostedCluster can optionally reference a configmap, in which case we copy
the configmap to the HostedControlPlane namespace (similar to SSHKey and
other fields).
When AdditionalTrustBundle is defined we create this ConfigMap to
align with the behavior of regular OCP clusters and enable
consumption of user-defined CA certs by the guest cluster.
When AdditionalTrustBundle is specified, we serialize the configmap and
pass to the MCO bootstrap command via the default user-ca-bundle-config.yaml
location - this means the MCO bootstrap will read the file when included,
(the code already ignores the case where the file doesn't exist, since
openshift/installer only conditionally creates the manifest)
Steven Hardy added 4 commits March 25, 2022 11:36
This can be used to reference a ConfigMap that contains a user CA
bundle.
The CPO and ignition server need the user CA so the registryclient
can access a local registry with a self-signed cert
Adds a CLI option and corresponding volume to the operator pod,
this is needed so the operator can look up release image metadata
when the release image specified is locally mirrored.

Note the mount path/filename were chosen to align with the expected
defaults ref https://go.dev/src/crypto/x509/root_linux.go (and also
current OCP docs for cert injection using operators)
@csrwng
Copy link
Contributor

csrwng commented Mar 25, 2022

@hardys looks like the verify is complaining about:

cmd/install/assets/hypershift_operator.go:418:40: k8s.io/api/core/v1.LocalObjectReference composite literal uses unkeyed fields

Other than that lgtm

@hardys
Copy link
Contributor Author

hardys commented Mar 25, 2022

@hardys looks like the verify is complaining about:

cmd/install/assets/hypershift_operator.go:418:40: k8s.io/api/core/v1.LocalObjectReference composite literal uses unkeyed fields

Other than that lgtm

Thanks I thought I fixed that in my latest push (previously I missed the Name in the LocalObjectReference) but will try to figure out why it's still failing as it's working fine locally now

@hardys
Copy link
Contributor Author

hardys commented Mar 25, 2022

/retest

[36mINFO�[0m[2022-03-25T11:37:25Z] Resolved source https://github.com/openshift/hypershift to main@339bea98, merging: #972 5b3d5162 @hardys 

Looks like it may be from before the push as the head of the branch is now 8fd5d43

@csrwng
Copy link
Contributor

csrwng commented Mar 25, 2022

/lgtm

@csrwng
Copy link
Contributor

csrwng commented Mar 25, 2022

/approve

@csrwng
Copy link
Contributor

csrwng commented Mar 25, 2022

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 25, 2022

@hardys: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-nested 8fd5d43 link false /test e2e-aws-nested

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@hardys
Copy link
Contributor Author

hardys commented Mar 28, 2022

/test capi-provider-agent-sanity

@csrwng
Copy link
Contributor

csrwng commented Mar 28, 2022

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 28, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 28, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: csrwng, hardys

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 28, 2022
@openshift-merge-robot openshift-merge-robot merged commit b9418cb into openshift:main Mar 28, 2022
hardys pushed a commit to hardys/hypershift that referenced this pull request Jul 28, 2022
In openshift#972 I relied on the fact that MCSIgnitionProvider mounts the MCO
ConfigMap under /assets/manifests - this means that the
user-ca-bundle-config.yaml file path matches the default location
from the MCO bootstrap code, thus no explicit
--additional-trust-bundle-config-file argument was required.

In openshift#1214 we introduced a new LocalIgnitionProvider, which unpacks the
MCO config to a different path e.g /payloads/get-payload123/config
hence we need to explicitly pass --additional-trust-bundle-config-file
or the additionalTrustBundle data is ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants