-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add optional token and secret-envs #361
feat: add optional token and secret-envs #361
Conversation
We need this because we're starting to get errors due to the rate limit imposed on PATs. |
Hi @NikitaCOEUR, can you rebase it (main is using the new version of common actions) FYI README files are auto updated regarding related action.yml files so you dont have to modify them. Thanks |
589db0a
to
a239b37
Compare
Hi @neilime, |
@neilime do you have some time to check it ? |
Hi @NikitaCOEUR, from what I understand, this PR allows to pass github app token for 2 use cases:
Can you explain me why you need to pass this custom token (instead of default GITHUB_TOKEN)? FYI, we have made some improvements based on some of your codes changes:
|
GITHUB_TOKEN does not have the right to interact with other private repositories in our organization. However, we can't use the application token generated by one job in another job (this is restricted to within the same job). This is why I wanted to enable the generation of the application token at the workflow level and map it to an ENV secret so that it could be reused in the same build. As far as checkouts are concerned, if the GITHUB_TOKEN allows us to interact with all the necessary repo, there's no need to use the token generated by the github app. |
@NikitaCOEUR The build images workflow is used in several private organizations without any issues. Are you sure the permissions are well configured: |
I think the problem we're having stems from the fact that we're using a PAT which we inject into our built images and which uses this token to download all the vendors, we're obliged to use a PAT given that some of the vendors are in our private repositories. Perhaps setting these repositories to "internal" would allow us to use GITHUB_TOKEN to download these vendors. The other solution is to use a Github APP token with the application configured to interact with our private repositories. Once again, we don't have a rights problem, only a rate-limit problem! And they only happen a few times... |
Ok so the issue is only for build arg token that should be an app token instead of PAT. No need for checking out, right? |
I'd decided to run everything through the Github App, but on reflection, I don't think it's necessary for checking out. You're right. |
@NikitaCOEUR can you try main branch it is supposed to match with your needs: Inputs This feature is battle tested: https://github.com/hoverkraft-tech/ci-github-container/blob/main/.github/workflows/__test-workflow-docker-build-images.yml#L59-L73 I guess we can close this PR. If you have any feedback, feel free to open an issue or a PR. Thanks |
Unfortunately, it doesn't work, because of the way the token is created here : https://github.com/hoverkraft-tech/ci-github-container/blob/main/.github/workflows/docker-build-images.yml#L345-L351 I created it like this: I specified the organization in order to generate a token that could access all the repositories to which the github application was authorized to access in our organization. By not specifying the organization, the generated token has restricted access to the current repository only :
It may be necessary to be able to specify certain parameters when generating the token, or to decide to add the organization directly. Otherwise, this token is no more interesting than the classic GITHUB_TOKEN. |
@NikitaCOEUR can you try last main version? |
Um, it's better regarding the creation of the token : On the other hand, there seems to be a problem with I think you forgot to publish the |
@NikitaCOEUR the export of GITHUB_APP_TOKEN env var is done there: https://github.com/hoverkraft-tech/ci-github-container/blob/main/.github/workflows/docker-build-images.yml#L376 And e2e test are ok by using custom
|
I set the ci-github-container/.github/workflows/__test-workflow-docker-build-images.yml Lines 70 to 73 in a381f65
So I think there's a problem with this step: ci-github-container/.github/workflows/docker-build-images.yml Lines 383 to 386 in a381f65
|
@neilime
Instead of :
Or something like that |
@NikitaCOEUR it should be good now |
Ah, I can see the whole command in the raw log |
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
@NikitaCOEUR here is PR that reproduce your usecase (empty It works fine: #372 |
The command line doesn't appear whole at runtime, but when you reload the view after the job has been executed, it does show the whole line. It works fine, but I get an access denied when composer install is run, it doesn't seem to be able to use the token generated for the github app, although I did manage to do so in my test jobs, but I wonder if it hadn't used a cached layer with a PAT-type token during my tests. For me, the changes you've made are working as they should. I'm trying to get the whole thing working now ... (I manage to reproduce locally using a simplified Dockerfile, I generate a token from my github app (token |
When composer executes git clone, it issues this command : Whereas, as specified here : https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation#about-authentication-as-a-github-app-installation
And when I try this command by hand, it works fine : |
Well, with this workaround, it works:
But, inevitably, a problem: a Maybe add a warning in the documentation? |
Pay attention that |
Can you prepare a release to take advantage of all these changes? |
@neilime I have just seen some elements of our CI failing due to rate limit and the problem is appearing here at the moment: |
@NikitaCOEUR the new version has been released: https://github.com/hoverkraft-tech/ci-github-container/releases/tag/0.21.0 |
This pull request includes significant updates to the GitHub Actions workflows and related documentation to support the use of GitHub Application tokens. The most important changes include adding new inputs and secrets for GitHub Application tokens, updating workflow steps to handle these tokens, and modifying related action files to support the new functionality.
Workflow Enhancements:
.github/workflows/docker-build-images.md
: Added new inputsapp-id
andapp-token-to-docker-secret-envs-keys
, and a new secretapp-key
to support GitHub Application tokens. [1] [2] [3].github/workflows/docker-build-images.yml
: Updated the workflow to include steps for creating a GitHub Application token, generating secrets, and using these tokens in the build process. [1] [2] [3] [4] [5] [6] [7]Action File Updates:
actions/docker/build-image/README.md
: Added descriptions for new inputssecret-envs
andtoken
for exposing secrets and using custom tokens. [1] [2]actions/docker/build-image/action.yml
: Added new inputssecret-envs
andtoken
, and updated steps to use these inputs. [1] [2] [3] [4]Metadata Action Updates:
actions/docker/get-image-metadata/README.md
: Added a new inputtoken
for using a custom token for repository checkout. [1] [2]actions/docker/get-image-metadata/action.yml
: Added a new inputtoken
, and updated steps to use this token. [1] [2] [3]These changes enhance the security and flexibility of the workflows by allowing the use of GitHub Application tokens, which can provide more granular permissions and better security practices.
How to use it
It will generate an installation token based on your installed Github Application and map secret named
GITHUB_TOKEN
to env varAPP_TOKEN
with generated token viaactions/create-github-app-token
.Note
We can NOT use application token instead of

oci-registry-password
for the moment, https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registriesWarning
Depends on hoverkraft-tech/ci-github-common#298 for
checkout ci-github-common/actions/checkout
a commit dedicated to switch to the new version is needed before merging this PR.