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

Using node pull credentials during builds, image stream imports and pull-through #136

Merged
merged 1 commit into from
Jan 29, 2020
Merged

Using node pull credentials during builds, image stream imports and pull-through #136

merged 1 commit into from
Jan 29, 2020

Conversation

ricardomaraschini
Copy link
Contributor

This commit added a proposal of using node's artifacts(pull secrets and
certificates) during image stream imports and builds.

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 3, 2019
@ricardomaraschini
Copy link
Contributor Author

/assign @adambkaplan @bparees @dmage @gabemontero

build and import image streams from this registry.
- Deploy an image registry using self-signed certificates and provide its pull
secrets and certificates after the install. Attempt to build and import image
streams from this registry.
Copy link
Contributor

Choose a reason for hiding this comment

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

missing test coverage for "run builds using images that can only be pulled using node credentials".

Needs to cover:

  1. pulling the base image
  2. pulling images being used for content extraction/input
  3. pushing images (This one may need more discussion... i'm not sure if we want to allow regular users to leverage the node credentials for pushing images to registries.. that feels like a bit of an escalation from what users can currently accomplish by way of the node credentials today)

Copy link
Contributor

Choose a reason for hiding this comment

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

pushing images (This one may need more discussion... i'm not sure if we want to allow regular users to leverage the node credentials for pushing images to registries.. that feels like a bit of an escalation from what users can currently accomplish by way of the node credentials today)

I agree pushing with the node credential presents a problem. I can foresee admins installing OpenShift with a pull secret that allows image push and not being aware that this pull secret could be used for push by anyone via builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been looking at the builder source code and we could use node credentials only during pull, never for push. If you are OK I would add another item under section "Risks and Mitigations" and a new test case for this scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we've got consensus on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to only using node creds for pull if pull secrets are otherwise not provided for the build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a new item under Risks and Mitigations to cover these aspects we have discussed on this thread. PTAL.

Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/cc @mfojtik @sttts @soltysh
for impacts to openshift-apiserver

/cc @umohnani8 @mrunalp
for node interactions

build and import image streams from this registry.
- Deploy an image registry using self-signed certificates and provide its pull
secrets and certificates after the install. Attempt to build and import image
streams from this registry.
Copy link
Contributor

Choose a reason for hiding this comment

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

pushing images (This one may need more discussion... i'm not sure if we want to allow regular users to leverage the node credentials for pushing images to registries.. that feels like a bit of an escalation from what users can currently accomplish by way of the node credentials today)

I agree pushing with the node credential presents a problem. I can foresee admins installing OpenShift with a pull secret that allows image push and not being aware that this pull secret could be used for push by anyone via builds.

@adambkaplan
Copy link
Contributor

@ricardomaraschini note that the node pull secret would be in addition to the pull secret for the internal registry, which is specific to each service account in a given namespace. Builds at minimum would need to search both pull secret files to find which credential to use.

@mrunalp
Copy link
Member

mrunalp commented Dec 4, 2019

@nalind ptal.

@ricardomaraschini ricardomaraschini changed the title Using node artifacts during build and image import Using node pull credentials during builds and image stream imports Dec 10, 2019
Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

@ricardomaraschini mostly nits, plus my note clarifying the behavior of pull secrets with builds.

Otherwise looks good!

enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
Copy link
Contributor

@bparees bparees left a comment

Choose a reason for hiding this comment

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

a few nits, otherwise lgtm

enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
enhancements/node-pull-credentials/pull-credentials.md Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 12, 2019
@ricardomaraschini ricardomaraschini changed the title Using node pull credentials during builds and image stream imports Using node pull credentials during builds, image stream imports and pull-through Dec 12, 2019
@ricardomaraschini
Copy link
Contributor Author

@dmage @adambkaplan I have submitted a new commit adding a comment on how we should treat if the namespace contains credentials that are also present on the node. PTAL.

#### Image Stream Import

- Mount the pull secret as `readOnly`, `hostPathreadOnly` in
`openshift-apiserver` deployment under `/node/var/lib/kubelet/config.json`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmage we need to come up with an agreement when it comes to the place where we are going to mount this. What is your idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

my idea is to use the same path inside the pod as on the node, but I'd like to hear ideas from someone who can approve PRs for openshift-apiserver.

Copy link
Contributor

Choose a reason for hiding this comment

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

and I'd say it should be configurable, i.e. the operator should mount /var/lib/kubelet/config.json and pass this name into the configuration file.

Copy link
Member

Choose a reason for hiding this comment

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

@csrwng we would also need to track mounting this into the hypershift-toolkit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following @dmage suggestion I have updated the proposal, now we mount pull secrets on /var/lib/kubelet/config.json

Mitigations:

As far as I verified(and this needs to be once more tested) it is impossible
to spawn a shell inside the builder pods. I also tried to copy the credentials
Copy link

Choose a reason for hiding this comment

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

Ephemeral pods will allow sharing process namespace and thus provide you with access to it. That's a major problem.

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This issue also applies to "openshift-apiserver" during image stream import or is something only for builds?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ricardomaraschini what @soltysh is saying is that even though we block oc rsh into a build-pod, someone (may) be able to create an ephemeral container in the build-pod's process namespace and use that mechanism to get into it instead.

@deads2k are there security mechanisms that would prevent someone from abusing this? much like we don't allow you to exec/rsh into a pod you can't "create" yourself (so normal users can't exec/rsh into a privileged container, as i understand it), does the ephemeral container api have similar restrictions?

Copy link
Member

Choose a reason for hiding this comment

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

@bparees there is no limitation at this time to my knowledge. its not clear to me that we could use rbac appropriately in a namespace to block the subresource to create the ephemeral container as build pods would be in the same namespace as other pods we would want to allow ephemeral access.

Copy link
Contributor

Choose a reason for hiding this comment

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

that subresource effectively updates the pod resource. If i can't create privileged pods, i would not expect to be able to edit prvileged pods and i'd expect that restriction to extend to subresources that modify the pod. No?

Copy link
Contributor

Choose a reason for hiding this comment

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

spoke with @derekwaynecarr offline. SCC will need to handle this (ensure that a user who can't create a particular pod also cannot invoke this subresource which edits the pod).

between @openshift/sig-developer-experience and @openshift/sig-master we need to ensure this is covered by the time the ephemeral container api goes beta (at which point it will be on by default).

Copy link
Contributor Author

@ricardomaraschini ricardomaraschini Jan 20, 2020

Choose a reason for hiding this comment

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

I have enabled EphemeralContainers on kube-apiserver and simulated the feature, as kubeadmin I have been able to patch the pod normally as expected but as a regular user I received the following message back:

$ oc replace --raw /api/v1/namespaces/build/pods/img-1-build/ephemeralcontainers -f ./ec.json 
Error from server (Forbidden): pods "img-1-build" is forbidden: User "user" cannot update resource "pods/ephemeralcontainers" in API group "" in the namespace "build"
$

ec.json:

$ cat ec.json 
{
    "apiVersion": "v1",
    "kind": "EphemeralContainers",
    "metadata": {
            "name": "img-1-build"
    },
    "ephemeralContainers": [{
        "command": [
            "sh"
        ],
        "image": "busybox",
        "imagePullPolicy": "IfNotPresent",
        "name": "debugger",
        "stdin": true,
        "tty": true,
        "terminationMessagePolicy": "File"
    }]
}

It might be that this is already supported by the current codebase.

- Allow users to run `builds` based on images hosted in any registry provided
during or after cluster installation without providing any extra credentials.
- Allow `image-registry` to execute pull-through using the node's pull
credentials.
Copy link

Choose a reason for hiding this comment

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

What I'm missing here is an explicit opt-in for that functionality, not every cluster-wide secret can and should be exposed. I see the requirement, but the risks are much higher, so this should not be a default, rather an opt-in.

Copy link
Contributor

Choose a reason for hiding this comment

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

@soltysh this enhancement is narrowly focused on the pull-secret added to the openshift-config namespace at install time. This pull secret is implicitly shared cluster-wide on all nodes - I am not aware of any opt-out other than deleting this secret.

I agree that a general "share any secret across a cluster" feature should absolutely be opt-in. DevEx has discussed this a bit as a future enhancement proposal [1]

[1] https://issues.redhat.com/browse/DEVEXP-426


This is the node's filesystem path we are taking into account:

- `/var/lib/kubelet/config.json` contains the node's pull secret.
Copy link
Contributor

Choose a reason for hiding this comment

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

can this file change? E.g. a user can ssh into the machine and append secrets there.

Copy link
Contributor

Choose a reason for hiding this comment

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

This has influence on openshift/cluster-openshift-apiserver-operator#284, i.e. we need to reread that file. Is that the case?

Copy link
Contributor

Choose a reason for hiding this comment

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

it can be changed via the MCO which causes node reboots so rereading is moot.

if the MCO is ever updated to allow node filesystem changes w/o rebooting the nodes, we'd have to setup a watch on the mounted file in our pod.

I believe these steps are what lead to the /var/lib/kubelet/config.json being updated:
https://docs.openshift.com/container-platform/4.3/openshift_images/managing-images/using-image-pull-secrets.html#images-update-global-pull-secret_using-image-pull-secrets

Copy link
Contributor Author

@ricardomaraschini ricardomaraschini Jan 27, 2020

Choose a reason for hiding this comment

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

Pull secrets are read in a "per image stream import request" basis, we don't keep it in memory.

This commit added a proposal of using node's pull secrets and during image
stream imports, image-registry pull-through operations and builds.
Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/lgtm

/assign @bparees

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 29, 2020
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan, ricardomaraschini

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-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 29, 2020
@openshift-merge-robot openshift-merge-robot merged commit b353002 into openshift:master Jan 29, 2020

Mitigations

Mounted path always exist on worker nodes.
Copy link
Contributor

Choose a reason for hiding this comment

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

what about master nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. The confirmation we have is that this path does not exist only on bootstrap nodes. @adambkaplan could we tag someone from node's team to get a final answer on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@cgwalters can you please confirm that the cluster pull secret always exists at /var/lib/kubelet/config.json

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 want to make that permanent "ABI" though; see also openshift/machine-config-operator#1190 which proposes ensuring all MCO configuration (including pull secret) lives in /etc so it can be made transactional - (but we'd probably have a backcompat symlink for a while at least).

I think probably the best bet is for whatever wants it to parse the kubelet config or so perhaps?

Or, I guess we could make /etc/kubernetes/pull-secret.json -> /var/lib/kubelet/config.json today and people could start using the new name. (Or probably better introduce the that new /etc name upstream)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to make that permanent "ABI" though; see also openshift/machine-config-operator#1190 which proposes ensuring all MCO configuration (including pull secret) lives in /etc so it can be made transactional - (but we'd probably have a backcompat symlink for a while at least).

It is clear that we must make the file path easily configurable.

I think probably the best bet is for whatever wants it to parse the kubelet config or so perhaps?

@cgwalters Do you mean to parse /etc/kubernetes/kubelet.conf to know from where to read pull secrets? I could not find any directive on it pointing to /var/lib/kubelet/config.json, pardon if I misunderstood you, could you clarify?

Or, I guess we could make /etc/kubernetes/pull-secret.json -> /var/lib/kubelet/config.json today and people could start using the new name. (Or probably better introduce the that new /etc name upstream)

I guess this would take some time to get done and we already have some PRs in place to implement this enhancement. I am inclined to stick with /var/lib/kubelet/config.json, making it easily configurable so we can easily migrate in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cgwalters are you going to change root-dir for kubelet?

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. 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.