-
Notifications
You must be signed in to change notification settings - Fork 34
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
Makefile, push: Prevent overwriting existing version tags #445
Makefile, push: Prevent overwriting existing version tags #445
Conversation
Makefile
Outdated
check-tag-exists: | ||
@echo "Checking if tag '${IMAGE_GIT_TAG}' exists in ${REGISTRY}/${IMG}..." | ||
@if skopeo inspect docker://${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} >/dev/null 2>&1; then \ | ||
echo "Tag '${IMAGE_GIT_TAG}' already exists. Skipping push."; \ | ||
exit 0; \ | ||
fi | ||
|
||
# Push the docker image | ||
docker-push: | ||
$(OCI_BIN) push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_TAG} | ||
$(OCI_BIN) tag ${REGISTRY}/${IMG}:${IMAGE_TAG} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} | ||
$(OCI_BIN) push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} | ||
@$(MAKE) check-tag-exists || \ | ||
( \ | ||
$(OCI_BIN) tag ${REGISTRY}/${IMG}:${IMAGE_TAG} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \ | ||
$(OCI_BIN) push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \ | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be simplified please to one target ? (something like this, but didn't check it is correct, just as a direction)
docker-push:
@echo "Checking if tag '${IMAGE_GIT_TAG}' exists in ${REGISTRY}/${IMG}..."
@if ! skopeo inspect docker://${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} >/dev/null 2>&1; then \
echo "Tag '${IMAGE_GIT_TAG}' does not exist. Pushing image..."; \
$(OCI_BIN) push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_TAG}; \
$(OCI_BIN) tag ${REGISTRY}/${IMG}:${IMAGE_TAG} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \
$(OCI_BIN) push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \
else \
echo "Tag '${IMAGE_GIT_TAG}' already exists. Skipping push."; \
fi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw it is raceful
lets say skopeo due to hiccup (but lets say tag exists), and then it entered the good path, and can override
need to assert the error of skopeo is not found, not any other error please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, DONE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE.
My only worry is that if they change the error format then it might break, but I'm over analyzing this thing, so let's just keep it like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
only thing that worth considering later if desired is if there are any side effects in case we match the last assertion
(when all the other branches didnt meet)
Please add in the description the flow of what you done that created it, it will help understanding when it happens and the solution / it's correctness |
ba18689
to
676c5d0
Compare
676c5d0
to
0c5cb46
Compare
DONE, PTAL |
Thanks please add the info you added to the commit to the PR desc it means in this case we will only have Worth to consider please to think how we can create releases on main that wont affect future branching There is also the possible race above, please take a look |
0c5cb46
to
c826215
Compare
yes, for follow up for sure.
fixed. PTAL |
Makefile
Outdated
$(OCI_BIN) tag ${REGISTRY}/${IMG}:${IMAGE_TAG} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \ | ||
$(OCI_BIN) push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \ | ||
else \ | ||
echo "Error checking for tag '${IMAGE_GIT_TAG}'. Aborting to avoid potential overwrite."; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need exit 1
so we will know it happens ?
needed if the tag can be mandatory on some cases (which i believe it does)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not mandatory but it doesn't hurt to know it failed on the gitActions.. Otherwise we'll never see it.
DONE
c826215
to
ff5cf5a
Compare
Thanks |
|
ff5cf5a
to
11cb4ac
Compare
my bad, forgot the |
Thanks btw |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RamLavi 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 |
|
11cb4ac
to
8394c23
Compare
For some reason it doesn't catch it, while locally it works:
|
maybe old skopeo ? |
could be. I'm thinking we drop the check, and if we see a race in the future we tackle it. |
if you drop the whole check, doesnt it mean it will always give wrong answer? |
8deb8a5
to
4635633
Compare
The IMAGE_GIT_TAG is generated using `git describe` to create a virtual tag for the image, and used in order to tag every push to the repository for later use. However, when an actual git tag exists (e.g., v0.45.0), git describe returns that tag. This behavior makes it possible to accidentally overwrite push an existing version tag in the registry. Flow Leading to the Issue: 1. A new kmp release is created, pushing a new tag (e.g., v0.45.0). 2. A stable branch is created from that commit, pushing a new stable branch tag (e.g., release-0.45_latest). 2.1 . During this push, IMAGE_GIT_TAG resolves to this Git tag (e.g., v0.45.0) due to git describe. 2.2 Makefile attempts to push the image with this tag (e.g., v0.45.0) to the registry, overwriting the original tag sha256 digest. To address this, introducing a check to ensure such tags are not overwritten when pushed to remote repositories, preserving the integrity of published versions. In case of local repositories the push to IMAGE_GIT_TAG is removed entirely. Signed-off-by: Ram Lavi <[email protected]>
18e5fd9
to
4f33dbf
Compare
@oshoval fixed the issue, PTAL |
What this PR does / why we need it:
The IMAGE_GIT_TAG is generated using
git describe
to create a virtualtag for the image, and used in order to tag every push to the repository
for later use.
However, when an actual git tag exists (e.g., v0.45.0), git describe
returns that tag. This behavior makes it possible to accidentally
overwrite push an existing version tag in the registry.
Flow Leading to the Issue:
branch tag (e.g., release-0.45_latest).
2.1 . During this push, IMAGE_GIT_TAG resolves to this Git tag (e.g.,
v0.45.0) due to git describe.
2.2 Makefile attempts to push the image with this tag (e.g., v0.45.0) to
the registry, overwriting the original tag sha256 digest.
To address this, introducing a check to ensure such tags are not
overwritten, preserving the integrity of published versions.
Special notes for your reviewer:
Release note: