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: Unpack config file in BuildDefinition #1547

Merged
merged 3 commits into from
Jan 24, 2023
Merged

Conversation

rbehjati
Copy link
Contributor

Fixes #1503

Signed-off-by: Razieh Behjati [email protected]

To unpack the input config file, even in case of dry-run we have to fetch the source, and load the config file. Because of this, some parts of builder.go are refactored as part of this PR. The benefit of this is that now dry-run and build commands now have more in common. In particular, dry-run performs more of the checks in build.

@rbehjati rbehjati force-pushed the unpack branch 2 times, most recently from 6bc7a92 to d4ec45b Compare January 18, 2023 15:34
@@ -208,13 +218,13 @@ jobs:
--build-config-path "${CONFIG_PATH}" \
--build-definition-path build-definition.json \
--builder-image "${BUILDER_IMAGE}@${BUILDER_DIGEST}" \
--git-commit-digest "sha1:${GITHUB_SHA}" \
--git-commit-digest "sha1:${{needs.commit.outputs.sha}}" \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, are you having trouble getting GITHUB_SHA? Hmmm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. In case of pull requests it is not the actual commit. I am trying to get the latest commit, but now I get the error fatal: not a git repository (or any of the parent directories): .git. This is very strange.

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 thought detect-env would give the correct sha, but it gives empty string.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohhh gotcha, for pull_request events it does appear GITHUB_SHA is not the triggering commit (https://github.com/orgs/community/discussions/26325). But for that, wouldn't the builder need to checkout the base repository (which may be the fork?)

I thought detect-env would give the correct sha, but it gives empty string.

detect-env gives the ref of the reusable workflow, not the triggering environment. hmmm. It should give the head sha of that, let me see if I can test that out as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But for that, wouldn't the builder need to checkout the base repository (which may be the fork?)

Yes, but even in that case the GITHUB_SHA we provide to the command is not something that exists on the repo.

It should be possible to get the actual commit hash. I have one more idea to try :)

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 detect-env has special case for pull requests to enable pre-submit tests. We don't really support it out outside of that context. The action may need to be adjusted.

@rbehjati rbehjati force-pushed the unpack branch 2 times, most recently from a7771cb to 0221010 Compare January 18, 2023 17:07
@@ -208,13 +220,13 @@ jobs:
--build-config-path "${CONFIG_PATH}" \
--build-definition-path build-definition.json \
--builder-image "${BUILDER_IMAGE}@${BUILDER_DIGEST}" \
--git-commit-digest "sha1:${GITHUB_SHA}" \
--git-commit-digest "sha1:${{ github.event.pull_request.head.sha }}" \
Copy link
Contributor Author

@rbehjati rbehjati Jan 18, 2023

Choose a reason for hiding this comment

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

With this change we are getting the correct commit sha, but I think we also need to specify the correct branch in source-repo. I am not sure if that is possible. I'll give it a try.

Also, this will fail if the event is push. We should be able to handle both cases.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC the head SHA will only be available for pull_request events? Are there other events you'll need to handle? I assume that the primary event you would need to handle is tag or release for when release tags are created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. We have to be able to handle all these events. I am thinking of reverting this back to use GITHUB_SHA, but make these steps conditional on events that are not pull_request, and add a separate step for pull_request.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we have a lot of places throughout that act differently for pull requests.

I'm curious how you are planning to support pull requests? we have the problem that id-token:write isn't available on pull requests (#131) so we aren't really able to sign provenance for those events currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For pull-requests we only run the dry-run command. We won't actually generate the provenance or sign, but just to make sure that the inputs are correct, and that we can create a BuildDefinition.

The idea is to allow the users to verify their workflow parameters before merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK so just to clarify what happens here now: actions/checkout by default checks out the github repo at the ref of the merge commit. I think that also references GITHUB_SHA, and so the comparison with the checked out repo and the GITHUB_SHA of the command line input should always match, pull request or not?

Yes. After all these experiments that is my understanding too. This behaviour makes sense, and makes things simpler :)

secondly, the new resolution-strategy will allow dry-run to create a build definition, ignoring the mismatch and using the current checkout for the source digest? if so, i think that makes sense.

True. But actually this feature is no longer required, at least not for GitHub. So we could either keep it, or drop it in favour of making the code simpler :)

what happens to the digest of the config file though? is it checked out at the current checkout or at the git-commit-digest during --resolution-strategy ignore? (It seems like ignore is like override with the current checkout so it uses the current checkout for the config file)

It is checked out at the current commit, or what I call the effective commit. The generated BuildDefinition also contains this effective commit digest, not the one given in the inputs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So we could either keep it, or drop it in favour of making the code simpler :)

Should we keep, and file a follow-up issue to clean it if the code is complete and we find it's not useful for testing?

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 can actually drop these changes easily, I just need to revert the last commit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

easy! thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I think this is now ready to be merged :)

@rbehjati rbehjati force-pushed the unpack branch 10 times, most recently from 301fa00 to e011dda Compare January 24, 2023 14:12
Copy link
Collaborator

@asraa asraa left a comment

Choose a reason for hiding this comment

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

one small nit, but otherwise lgtm. thank you for all the documentation!

internal/builders/docker/pkg/options.go Show resolved Hide resolved
Signed-off-by: Razieh Behjati <[email protected]>
Signed-off-by: Razieh Behjati <[email protected]>
@asraa asraa merged commit 7739525 into slsa-framework:main Jan 24, 2023
@rbehjati rbehjati deleted the unpack branch January 24, 2023 15:46
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.

[feature] Expand the content of the config file in the BuildDefinition
3 participants