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 smoke tests for encryption CLI helpers #4745

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

mtrmac
Copy link
Contributor

@mtrmac mtrmac commented Apr 18, 2023

What type of PR is this?

/kind other

What this PR does / why we need it:

A non-nil but empty decryption configuration seems to be valid enough to trigger decryption in some configurations, per containers/podman#18196 .

Like in Skopeo and Podman, only decrypt when the user explicitly instructs us to (e.g. not triggering decryption based on environment variables).

How to verify it

Manually, I guess.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Does this PR introduce a user-facing change?

An explicit `--decryption-key` option is now mandatory to trigger image decryption, even if the environment implicitly points at usable keys.

@mtrmac
Copy link
Contributor Author

mtrmac commented Apr 18, 2023

Cc: @lumjjb

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM , this needs [NO NEW TESTS NEEDED]

@Luap99
Copy link
Member

Luap99 commented Apr 19, 2023

I am not a buildah maintainer so ultimately I do not really care but this sounds like a breaking change. If you now require the option explicitly this can break existing users that depend on it. We should avoid such changes at all costs.

@mtrmac
Copy link
Contributor Author

mtrmac commented Apr 19, 2023

Note #4746 as an alternative implementation approach.


this sounds like a breaking change. If you now require the option explicitly this can break existing users that depend on it.

Yes… but it was also, to my knowledge, never documented in Buildah to work this way. I don’t know for sure whether it was intended to work this way, or documented elsewhere to work this way.

I’ll defer to @lumjjb on that.


We should avoid such changes at all costs.

I don’t think we have a general obligation to be bug-for-bug-compatible, and I would fairly strongly push against being bug-for-bug-compatible “at all costs”.

Still, it’s a valid concern. I can imagine changing podman pull to auto-decrypt instead — although it feels unintuitive and vaguely possibly risky to me.


Most of the diagnosis and discussion has been in containers/podman#18196 , and there are two Buildah PRs in flight.

Let’s concentrate the design discussion in the Podman containers/podman#18196 issue, for now.

@mtrmac mtrmac force-pushed the explicit-decrypt branch from 470cbcb to 49d0d54 Compare April 19, 2023 18:16
@mtrmac
Copy link
Contributor Author

mtrmac commented Apr 19, 2023

LGTM , this needs [NO NEW TESTS NEEDED]

Thanks for pointing that out.

Actually I would expect some of the existing tests to fail with a different error message, so bypassing that for now to see the real failures…

@mtrmac mtrmac marked this pull request as draft April 19, 2023 18:17
@mtrmac mtrmac force-pushed the explicit-decrypt branch from 49d0d54 to 2e92317 Compare April 19, 2023 19:47
@rhatdan
Copy link
Member

rhatdan commented Apr 19, 2023

I am fine with making them consistent since buildah vendored into Podman means podman build works differently then podman pull.

@TomSweeneyRedHat
Copy link
Member

Anyway to add a warning? I.e. if the environment points at keys, but the option is not specified, then print a warning message? IDK for sure that we would want to do that, but just wondering.

@mtrmac
Copy link
Contributor Author

mtrmac commented Apr 20, 2023

Anyway to add a warning? I.e. if the environment points at keys, but the option is not specified, then print a warning message? IDK for sure that we would want to do that, but just wondering.

If the image isn’t encrypted, we probably wouldn’t want to warn:

  • Right now, we “enable” encryption for all buildah from cases, only it does nothing for unencrypted images
  • And to avoid that warning, users would probably need to unset the environment variable… which is a hassle.

OTOH if the image is encrypted and we no longer decrypt by default, buildah from will fail (see the test suite updates in this PR), so we don’t need a warning. The error message in that case could certainly be improved — but that’s not this PR; it would probably be added in c/image.

@mtrmac mtrmac force-pushed the explicit-decrypt branch from 2e92317 to e795044 Compare April 20, 2023 19:24
tests/from.bats Outdated
@@ -427,8 +427,8 @@ load helpers
run_buildah push $WITH_POLICY_JSON --tls-verify=false --creds testuser:testpassword --encryption-key jwe:${TEST_SCRATCH_DIR}/tmp/mykey.pub busybox oci:${TEST_SCRATCH_DIR}/tmp/busybox_enc

# Try encrypted image without key should fail
run_buildah 125 from oci:${TEST_SCRATCH_DIR}/tmp/busybox_enc
expect_output --substring "decrypting layer .* missing private key needed for decryption"
run_buildah 1 from oci:${TEST_SCRATCH_DIR}/tmp/busybox_enc
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 exit code changes because the error stack, ultimately, contains an exec.ExitError from invoking an untar subprocess; and the top level of Buildah checks for exec.ExitError, and returns that exit code.

One can read that as a failure of the Go error wrapping design… or, alternatively, as Builder’s main matching too loosely if it wants only specific subprocesses’ exit codes to be returned unmodified.

AFAICS the exit code from Buildah is, apart from buildah manifest exists, not documented, so this PR just changes tests to accept the status 1. If we do actually commit (whether in documentation in or in practice) to returning 125 on unspecific failures, and this needs to be made more precise, please let me know (and also define which subprocess invocations that could fail with ExitError should be propagated.)

@rhatdan
Copy link
Member

rhatdan commented Apr 21, 2023

We only document the exit codes for the run commands, I believe.

The question is do we take this PR and leave multiple implementation of the same code, or take mine and vendor the code into Podman.

@mtrmac
Copy link
Contributor Author

mtrmac commented Apr 21, 2023

I think the primary question is whether we want this; as @Luap99 points out, this might be a compatibility break.

If we do want this, I completely agree that sharing the code, per your PR, is the better approach — consider using the test updates from here, to make it pass.

@rhatdan
Copy link
Member

rhatdan commented Apr 22, 2023

I don't see this as an important breaking change, since having it two different ways within Podman is more important.
LGTM
I think we can merge this and then I will update my PR to pull this in.

@mtrmac mtrmac marked this pull request as ready for review April 24, 2023 15:40
@mtrmac mtrmac force-pushed the explicit-decrypt branch from e795044 to 1bb65e2 Compare April 24, 2023 15:44
@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@mtrmac
Copy link
Contributor Author

mtrmac commented May 25, 2023

(I think the consensus is to prefer #4746 … except that it doesn’t build.)

@github-actions github-actions bot removed the stale-pr label May 26, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2023
@mtrmac mtrmac force-pushed the explicit-decrypt branch from a7691d5 to bdd27d3 Compare June 13, 2023 17:39
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2023
@mtrmac mtrmac changed the title Don't decrypt images by default Add smoke tests for encryption CLI helpers Jun 13, 2023
@mtrmac
Copy link
Contributor Author

mtrmac commented Jun 13, 2023

#4746 has implemented the primary (and better) fix; this now just carries the remaining unit tests.

@rhatdan
Copy link
Member

rhatdan commented Jun 13, 2023

/approve
/lgtm
/hold

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtrmac, rhatdan

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

@rhatdan
Copy link
Member

rhatdan commented Jun 14, 2023

/hold cancel

@rhatdan rhatdan merged commit 2935999 into containers:main Jun 14, 2023
@mtrmac mtrmac deleted the explicit-decrypt branch June 14, 2023 14:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants