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

MGMT-16508: Add API to AgentServiceConfig CRD to allow pass of CA certificates for image pull. #5884

Merged
merged 1 commit into from Jan 30, 2024

Conversation

paul-maidment
Copy link
Contributor

@paul-maidment paul-maidment commented Jan 15, 2024

MGMT-16508: Add API to AgentServiceConfig CRD to allow pass of CA certificates for image pull.

This PR introduces a new field to the AgentServiceConfig CRD imagePullCAConfigMap which is a LocalObjectReference to a config map containing CA certificates
These certificates are to be used by the image service for the purpose of verifying the CA of HTTPS connections used for pulling images.

imagePullConfigMap is expected to reference a ConfigMap containing a single file extra-ca.pem which contains the CA certificate.
If multiple CA certificates are to be used, the user is expected to append these into the same PEM.

This code also passes the path ADDITIONAL_CA_FILE to the image service if the additional CA file is present.

This code sets up the Volume for this and maps to either an empty directory or maps the content of the ConfigMap.

This will ensure that the CA's will be available for use by the image service.

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • [] This change does not require a documentation update (docstring, docs, README, etc)
    Docstrings have been updated to describe the purpose of this change.
    There is also a ticket in the Epic to support more general documentation.
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 15, 2024

@paul-maidment: This pull request references MGMT-16508 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

This PR introduces a new field to the AgentServiceConfig CRD imagePullCAConfigMap which is a LocalObjectReference to a config map containing CA certificates These certificates are to be used by the image service for the purpose of verifying the CA of HTTPS connections used for pulling images.

If imagePullCAConfigMap has an influence over a volume definition for "additional-ca-bundle" in the StatefulSet for assisted-image-service. Any certificates defined within the data section of the map are to be stored in "/additional-ca-bundle"

This code sets up the Volume for this and maps to either an empty directory or maps the content of the ConfigMap.

This will ensure that the CA's will be available for use by the image service.

List all the issues related to this PR

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • [] This change does not require a documentation update (docstring, docs, README, etc)
    Docstrings have been updated to describe the purpose of this change.
    There is also a ticket in the Epic to support more general documentation.
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 15, 2024
@openshift-ci openshift-ci bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 15, 2024
@openshift-ci openshift-ci bot added api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 15, 2024
@paul-maidment paul-maidment force-pushed the MGMT-16508 branch 2 times, most recently from 692ceb3 to 2adc972 Compare January 15, 2024 08:59
@openshift-ci openshift-ci bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 15, 2024
Copy link

codecov bot commented Jan 15, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (dd3e90d) 68.18% compared to head (c4f131d) 68.21%.
Report is 2 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5884      +/-   ##
==========================================
+ Coverage   68.18%   68.21%   +0.02%     
==========================================
  Files         236      236              
  Lines       34788    34836      +48     
==========================================
+ Hits        23721    23763      +42     
- Misses       8999     9002       +3     
- Partials     2068     2071       +3     
Files Coverage Δ
...oller/controllers/agentserviceconfig_controller.go 85.08% <81.63%> (+0.07%) ⬆️

... and 2 files with indirect coverage changes

@paul-maidment
Copy link
Contributor Author

/retest

@gamli75
Copy link
Contributor

gamli75 commented Jan 18, 2024

@avishayt @carbonin please review

@paul-maidment paul-maidment force-pushed the MGMT-16508 branch 5 times, most recently from 2fe86ed to 0a38c5a Compare January 18, 2024 15:12
@paul-maidment
Copy link
Contributor Author

/retest

@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 18, 2024

@paul-maidment: This pull request references MGMT-16508 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

MGMT-16508: Add API to AgentServiceConfig CRD to allow pass of CA certificates for image pull.

This PR introduces a new field to the AgentServiceConfig CRD imagePullCAConfigMap which is a LocalObjectReference to a config map containing CA certificates
These certificates are to be used by the image service for the purpose of verifying the CA of HTTPS connections used for pulling images.

imagePullConfigMap is expected to reference a ConfigMap containing a single file extra-ca.pem which contains the CA certificate.
If multiple CA certificates are to be used, the user is expected to append these into the same PEM.

This code also passes the path ADDITIONAL_CA_FILE to the image service if the additional CA file is present.

This code sets up the Volume for this and maps to either an empty directory or maps the content of the ConfigMap.

This will ensure that the CA's will be available for use by the image service.

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • [] This change does not require a documentation update (docstring, docs, README, etc)
    Docstrings have been updated to describe the purpose of this change.
    There is also a ticket in the Epic to support more general documentation.
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

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 openshift-eng/jira-lifecycle-plugin repository.

1 similar comment
@openshift-ci-robot
Copy link

openshift-ci-robot commented Jan 18, 2024

@paul-maidment: This pull request references MGMT-16508 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

MGMT-16508: Add API to AgentServiceConfig CRD to allow pass of CA certificates for image pull.

This PR introduces a new field to the AgentServiceConfig CRD imagePullCAConfigMap which is a LocalObjectReference to a config map containing CA certificates
These certificates are to be used by the image service for the purpose of verifying the CA of HTTPS connections used for pulling images.

imagePullConfigMap is expected to reference a ConfigMap containing a single file extra-ca.pem which contains the CA certificate.
If multiple CA certificates are to be used, the user is expected to append these into the same PEM.

This code also passes the path ADDITIONAL_CA_FILE to the image service if the additional CA file is present.

This code sets up the Volume for this and maps to either an empty directory or maps the content of the ConfigMap.

This will ensure that the CA's will be available for use by the image service.

  • New Feature
  • Enhancement
  • Bug fix
  • Tests
  • Documentation
  • CI/CD

What environments does this code impact?

  • Automation (CI, tools, etc)
  • Cloud
  • Operator Managed Deployments
  • None

How was this code tested?

  • assisted-test-infra environment
  • dev-scripts environment
  • Reviewer's test appreciated
  • Waiting for CI to do a full test run
  • Manual (Elaborate on how it was tested)
  • No tests needed

Checklist

  • Title and description added to both, commit and PR.
  • Relevant issues have been associated (see CONTRIBUTING guide)
  • [] This change does not require a documentation update (docstring, docs, README, etc)
    Docstrings have been updated to describe the purpose of this change.
    There is also a ticket in the Epic to support more general documentation.
  • Does this change include unit-tests (note that code changes require unit-tests)

Reviewers Checklist

  • Are the title and description (in both PR and commit) meaningful and clear?
  • Is there a bug required (and linked) for this change?
  • Should this PR be backported?

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 openshift-eng/jira-lifecycle-plugin repository.

// this certificate will be used by the assisted-image-service when pulling OS images.
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Image pull CA config map reference"
// +optional
ImagePullCAConfigMapRef *corev1.LocalObjectReference `json:"imagePullCAConfigMapRef,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

I think this should reference OSImages in some way to make sure it's not confused with pulling container images.

Maybe OSImageCACertRef?

@@ -109,6 +109,12 @@ type AgentServiceConfigSpec struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="List of container registries without authentication"
// +optional
UnauthenticatedRegistries []string `json:"unauthenticatedRegistries,omitempty"`
// ImagePullCAConfigMapRef is a reference to a config map containing a certificate authority certificate
Copy link
Member

Choose a reason for hiding this comment

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

Can you just add a blank line between all the fields and the next field comment?
I see it's inconsistent in this struct, but we can fix that now.

@@ -109,6 +109,12 @@ type AgentServiceConfigSpec struct {
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="List of container registries without authentication"
// +optional
UnauthenticatedRegistries []string `json:"unauthenticatedRegistries,omitempty"`
// ImagePullCAConfigMapRef is a reference to a config map containing a certificate authority certificate
// this is an optional certificate to allow a customer to add a certificate authority for a HTTPS source of images
Copy link
Member

Choose a reason for hiding this comment

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

s/customer/user/

Comment on lines 1266 to 1275
// Read the referenced ConfigMap to ensure that it contains a single file "extra-ca.crt"
additionalCABundleCM := &corev1.ConfigMap{}
if err := asc.Client.Get(ctx, types.NamespacedName{Name: asc.spec.ImagePullCAConfigMapRef.Name, Namespace: asc.namespace}, additionalCABundleCM); err != nil {
log.WithError(err).Errorf("Failed to get additional CA Bundle config map %s", asc.spec.ImagePullCAConfigMapRef.Name)
return err
}
var err error
_, ok := additionalCABundleCM.Data["extra-ca.pem"]
if !ok {
err = multierror.Append(err, fmt.Errorf("expected to find single file `extra-ca.pem` in the ConfigMap %s but it was not found", asc.spec.ImagePullCAConfigMapRef.Name))
}
if len(additionalCABundleCM.Data) != 1 {
err = multierror.Append(err, fmt.Errorf("found multiple files in ConfigMap %s, a single file was expected but %d files were found", asc.spec.ImagePullCAConfigMapRef.Name, len(additionalCABundleCM.Data)))
}
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

I feel like all this validation doesn't belong in the StatefulSet mutate function.

I'd say this should be in the validate function and we should set a condition if any of the references are invalid.

volumes = ensureVolume(volumes, corev1.Volume{
Name: "additional-ca-bundle",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
Copy link
Member

Choose a reason for hiding this comment

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

We're not putting anything here in this case so the volume and volume mount should be added only if we have certs to add.

Comment on lines 1285 to 1295
volumeSource := &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: asc.spec.ImagePullCAConfigMapRef.Name,
},
}
volumes = ensureVolume(volumes, corev1.Volume{
Name: "additional-ca-bundle",
VolumeSource: corev1.VolumeSource{
ConfigMap: volumeSource,
},
})
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need the volumeSource intermediate variable here I'd just put it all in one struct.

@@ -1177,6 +1178,7 @@ func newImageServiceStatefulSet(ctx context.Context, log logrus.FieldLogger, asc
{Name: "tls-certs", MountPath: "/etc/image-service/certs"},
{Name: "service-cabundle", MountPath: "/etc/image-service/ca-bundle"},
{Name: "image-service-data", MountPath: "/data"},
{Name: "additional-ca-bundle", MountPath: "/additional-ca-bundle"},
Copy link
Member

Choose a reason for hiding this comment

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

Maybe put this in /etc/image-service like the others. How about /etc/image-service/os-images-ca-bundle?

@paul-maidment
Copy link
Contributor Author

/retest

2 similar comments
@paul-maidment
Copy link
Contributor Author

/retest

@paul-maidment
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 24, 2024
@carbonin
Copy link
Member

/hold

Just thought of this. Are we doing anything to ensure we update the image service when the contents of this config map change?
Are we doing something like that currently for the other reference?

@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 Jan 24, 2024
@paul-maidment
Copy link
Contributor Author

paul-maidment commented Jan 24, 2024

/hold

Just thought of this. Are we doing anything to ensure we update the image service when the contents of this config map change? Are we doing something like that currently for the other reference?

When you make a change to the content of the ConfigMap these are kept in sync automatically, I actually believe this is core functionality in Kubernetes.

There doesn't appear to be a redeployment but the volume is simply kept in sync, if you shell into the image service then you can see the files being updated within 30 seconds of any change to the ConfigMap

As we can see in this excerpt of the statefulset, there is a reference to the ConfigMap in the volume, I think Kubernetes must be watching these ConfigMaps.

...
      volumes:
      - name: tls-certs
        secret:
          defaultMode: 420
          secretName: assisted-image-service
      - configMap:
          defaultMode: 420
          name: assisted-image-service
        name: service-cabundle
      - configMap:
          defaultMode: 420
          name: image-service-additional-ca
        name: additional-ca-bundle
...

I would assume this is similar for EnvFrom.
Of course, this alone does not cause the statefulset to redeploy, so we probably have to handle that anyway.

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 25, 2024
@paul-maidment
Copy link
Contributor Author

/retest

@@ -1712,6 +1743,7 @@ func newAssistedServiceDeployment(ctx context.Context, log logrus.FieldLogger, a
setAnnotation(meta, assistedConfigHashAnnotation, assistedConfigHash)
setAnnotation(meta, mirrorConfigHashAnnotation, mirrorConfigHash)
setAnnotation(meta, userConfigHashAnnotation, userConfigHash)
setAnnotation(meta, osImagesCAConfigHashAnnotation, osImagesCAConfigHash)
Copy link
Member

Choose a reason for hiding this comment

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

This should be being set on the image service, not assisted.

Copy link

openshift-ci bot commented Jan 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: paul-maidment

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

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

Last nit. Otherwise looks good.

@@ -168,6 +171,7 @@ func initASC(r *AgentServiceConfigReconciler, instance *aiv1beta1.AgentServiceCo
return asc
}

type NewStatefulSetFn func(context.Context, logrus.FieldLogger, ASC) (*appsv1.StatefulSet, controllerutil.MutateFn)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should be defined here if it's only used in tests.

Copy link
Member

Choose a reason for hiding this comment

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

You are also only using AssertReconcileSuccessStatefulSetFn in one place. Maybe just don't define that function and then you wouldn't need this type.

…tificates for image pull.

This PR introduces a new field to the AgentServiceConfig CRD `imagePullCAConfigMap` which is a LocalObjectReference to a config map containing CA certificates
These certificates are to be used by the image service for the purpose of verifying the CA of HTTPS connections used for pulling images.

`imagePullConfigMap` is expected to reference a ConfigMap containing a single file `extra-ca.pem` which contains the CA certificate.
If multiple CA certificates are to be used, the user is expected to append these into the same PEM.

This code also passes the path `ADDITIONAL_CA_FILE` to the image service if the additional CA file is present.

This code sets up the Volume for this and maps to either an empty directory or maps the content of the ConfigMap.

This will ensure that the CA's will be available for use by the image service.
@carbonin
Copy link
Member

/unhold

1 similar comment
@carbonin
Copy link
Member

/unhold

@carbonin
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jan 29, 2024
@carbonin
Copy link
Member

/retest

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 7dbb3b1 and 2 for PR HEAD c4f131d in total

@openshift-merge-bot openshift-merge-bot bot merged commit 268d4ed into openshift:master Jan 30, 2024
15 of 17 checks passed
@openshift-bot
Copy link
Contributor

[ART PR BUILD NOTIFIER]

This PR has been included in build ose-agent-installer-api-server-container-v4.16.0-202401302041.p0.g268d4ed.assembly.stream for distgit ose-agent-installer-api-server.
All builds following this will include this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants