Browse Source

fix: prevent is-fork (#4671)

* fix: prevent is-fork

Signed-off-by: Gustavo Carvalho <gustavo@externalsecrets.com>

* fix: syntax

Signed-off-by: Gustavo Carvalho <gustavo@externalsecrets.com>

---------

Signed-off-by: Gustavo Carvalho <gustavo@externalsecrets.com>
Gustavo Fernandes de Carvalho 1 year ago
parent
commit
25f515d5f0

+ 1 - 0
.github/workflows/ci.yml

@@ -170,4 +170,5 @@ jobs:
       username: ${{ github.actor }}
       username: ${{ github.actor }}
     secrets:
     secrets:
       GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
       GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      IS_FORK: ${{ secrets.GHCR_USERNAME }} # this is just a secret to verify it is a fork or not, no other utility
 
 

+ 6 - 5
.github/workflows/publish.yml

@@ -34,13 +34,14 @@ on:
     secrets:
     secrets:
       GHCR_TOKEN:
       GHCR_TOKEN:
         required: true
         required: true
+      IS_FORK:
+        required: false
 
 
 env:
 env:
   IMAGE_NAME: ${{ inputs.image-name }}
   IMAGE_NAME: ${{ inputs.image-name }}
   TAG_SUFFIX: ${{ inputs.tag-suffix }}
   TAG_SUFFIX: ${{ inputs.tag-suffix }}
   ARCH: ${{ inputs.build-arch }}
   ARCH: ${{ inputs.build-arch }}
   DOCKERFILE: ${{ inputs.dockerfile }}
   DOCKERFILE: ${{ inputs.dockerfile }}
-  IS_FORK: ${{ secrets.GHCR_USERNAME == '' && 'true' || 'false' }}
 
 
 jobs:
 jobs:
   build-publish:
   build-publish:
@@ -86,7 +87,7 @@ jobs:
 
 
       - name: Login to Docker
       - name: Login to Docker
         uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
         uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
-        if: env.IS_FORK == 'false'
+        if: secrets.IS_FORK != ''
         with:
         with:
           registry: ghcr.io
           registry: ghcr.io
           username: ${{ inputs.username }}
           username: ${{ inputs.username }}
@@ -111,7 +112,7 @@ jobs:
           echo "image-tag=${TAG}" >> $GITHUB_OUTPUT
           echo "image-tag=${TAG}" >> $GITHUB_OUTPUT
 
 
       - name: Build & Publish Artifacts
       - name: Build & Publish Artifacts
-        if: env.IS_FORK == 'false'
+        if: secrets.IS_FORK != ''
         shell: bash
         shell: bash
         env:
         env:
           IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
           IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
@@ -122,7 +123,7 @@ jobs:
         run: make docker.build
         run: make docker.build
 
 
       - name: Build & Publish Artifacts fork
       - name: Build & Publish Artifacts fork
-        if: env.IS_FORK == 'true'
+        if: secrets.IS_FORK == ''
         shell: bash
         shell: bash
         env:
         env:
           IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
           IMAGE_TAG: ${{ steps.container_info.outputs.image-tag }}
@@ -151,7 +152,7 @@ jobs:
       - name: Checkout
       - name: Checkout
         uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
         uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
       - name: Sign image
       - name: Sign image
-        if: env.IS_FORK == 'false'
+        if: secrets.IS_FORK != ''
         uses: ./.github/actions/sign
         uses: ./.github/actions/sign
         with:
         with:
           image-name: ${{ inputs.image-name }}
           image-name: ${{ inputs.image-name }}

+ 1 - 0
.github/workflows/rebuild-image.yml

@@ -68,3 +68,4 @@ jobs:
       username: ${{ github.actor }}
       username: ${{ github.actor }}
     secrets:
     secrets:
       GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
       GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      IS_FORK: ${{ secrets.GHCR_USERNAME }}