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

fix: search $DOCKER_CONFIG if no base64 config is provided #398

Merged
merged 11 commits into from
Oct 30, 2024

Conversation

mafredri
Copy link
Member

Fixes #392

@mafredri mafredri self-assigned this Oct 28, 2024
@mafredri mafredri force-pushed the mafredri/fix-docker-config-path branch from b34692e to 147ba65 Compare October 28, 2024 16:04
@mafredri mafredri force-pushed the mafredri/fix-docker-config-path branch from 147ba65 to 8c0198f Compare October 28, 2024 16:05
envbuilder.go Outdated Show resolved Hide resolved
integration/integration_test.go Outdated Show resolved Hide resolved
@mafredri
Copy link
Member Author

CI seems to have issue with privilege and remounting, not sure why it applies to my test and not others. Looking into it.

Also realized we'll have to copy over config.json or change DOCKER_CONFIG to the remounted path if applicable.

// Remove the Docker config secret file!
if err := cleanupDockerConfigOverride(); err != nil {
return err
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Review: Moved this higher up so that when we reset DOCKER_CONFIG, we don't interfere with envbuilder trying to set envs from the build/devcontainer.

@mafredri mafredri force-pushed the mafredri/fix-docker-config-path branch 5 times, most recently from 2f1992e to 54fe86d Compare October 28, 2024 19:29
@mafredri mafredri force-pushed the mafredri/fix-docker-config-path branch from 54fe86d to 5da2aaa Compare October 28, 2024 19:33
require.NoError(t, err)

require.Contains(t, logbuf.String(), "Set DOCKER_CONFIG to /.envbuilder")
require.NotContains(t, logbuf.String(), "Using DOCKER_CONFIG at ")
Copy link
Contributor

@SasSwart SasSwart Oct 29, 2024

Choose a reason for hiding this comment

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

Do we generally trust log output for test assertions if we aren't testing logs?

If this log line ever drifts, this test will become a silent false positive. Is there a practical way to assert against the actual behaviour of the system? Could we copy the written docker config secret file so that it makes its way into the container and then assert against its contents?

Would that approach be worth it?

Copy link
Member

@johnstcn johnstcn Oct 29, 2024

Choose a reason for hiding this comment

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

We could modify ENVBUILDER_INIT_SCRIPT to write the content of $DOCKER_CONFIG and check the value from inside the container

Copy link
Member Author

Choose a reason for hiding this comment

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

@SasSwart good points, I agree, in general it’s best to test behavior and not output. @johnstcn I wanted to do that here but we can’t do it in the init script since it runs after cleanup.

Not sure if it’ll work but we could try to copy it as part of Dockerfile build instructions, will look into that.

Copy link
Member Author

@mafredri mafredri Oct 29, 2024

Choose a reason for hiding this comment

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

Went back to the drawing board with the implementation, changed the behavior for user-provided config files and converted the integration tests to primarily testing behavior.

@mafredri mafredri force-pushed the mafredri/fix-docker-config-path branch from 78d72f3 to 86db5a5 Compare October 29, 2024 17:47
require.Equal(t, want, got)
}

// Ensure that a warning message is printed if config secrets
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we only warn on this? Users may have a reason to use a DOCKER_CONFIG at build time and they may have a reason to use one at run time. But those are separate use cases as far as I can tell. Should we allow the line between the two to blur?

Would it be more secure and user friendly to treat build time DOCKER_CONFIG like a build secret; ensuring that it's always cleared?

Runtime secrets could then be provided using a runtime mechanism? Right users are mounting it in, but to me this would be treated just like any other runtime secret.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do we only warn on this? Users may have a reason to use a DOCKER_CONFIG at build time and they may have a reason to use one at run time. But those are separate use cases as far as I can tell. Should we allow the line between the two to blur?

That's a valid question. We can't determine the user's intent here. I'd say it's more likely that a given DOCKER_CONFIG is intended for build time since there's no guarantee Docker will be available in the resulting devcontainer.

Adding to this, if the devcontainer should have a DOCKER_CONFIG set at runtime, that should be done via containerEnv in devcontainer.json, not on the envbuilder container.

Would it be more secure and user friendly to treat build time DOCKER_CONFIG like a build secret; ensuring that it's always cleared?

Perhaps, but this ties into why we "only warn". We can't guarantee that we'll be able to wipe the secrets if the user has mounted them in, possibly as read-only, and the container doesn't have unmount permissions (or, will remounting be possible if there's sudo?). That's why we only warn and don't attempt to clear. If we attempted something else, we may risk introducing behavior that varies depending on the environment it's run in. It's better if the user knows what to expect.

Also, since we restore the original DOCKER_CONFIG, we're allowing that config location to be used at runtime, enabling use-cases where you have a separate build and runtime config. You set the build config via base64 env (takes precedence), and after the build, the location will be used at runtime. As a side-effect, the same config can be used for both build and runtime, which might not be ideal, but what's the alternative?

Runtime secrets could then be provided using a runtime mechanism? Right users are mounting it in, but to me this would be treated just like any other runtime secret.

Not sure what you're referring to by runtime secret and runtime mechanism? Could you expand on this?

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

I like this approach of warning the user.
If possible, I'd also like to see the documentation around registry auth updated either as part of this PR or as a follow-up.

continue
}

logf(log.LevelWarn, "Found Docker config at %s, this file will remain after the build", path)
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +679 to +683
// Always verify that the Docker configuration secret file is removed.
output := execContainer(t, ctrID, "stat "+configJSONContainerPath)
require.Contains(t, output, "No such file or directory")
})
}
Copy link
Member

Choose a reason for hiding this comment

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

👍 👍

@mafredri mafredri changed the title fix: always set DOCKER_CONFIG unless manually set and no base64 config provided fix: search $DOCKER_CONFIG if no base64 config is provided Oct 30, 2024
@mafredri mafredri enabled auto-merge (squash) October 30, 2024 16:52
@mafredri mafredri merged commit c4b082e into main Oct 30, 2024
4 checks passed
@mafredri mafredri deleted the mafredri/fix-docker-config-path branch October 30, 2024 16:57
mafredri added a commit that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow mounting in DOCKER_CONFIG again
3 participants