Skip to content

fix(ci): Permissions and depdendencies #772

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

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build_changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ name: Build changelog
on:
workflow_dispatch:

permissions:
contents: read

jobs:
changelog:
uses: ./.github/workflows/reusable_publish_changelog.yml
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
schedule:
- cron: '42 8 * * 0'

permissions:
contents: read

jobs:
analyze:
name: Analyze
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows/dispatch_analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ on:
- cron: '0 * * * *'

permissions:
id-token: write
actions: read
checks: read
contents: read
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read

jobs:
dispatch_token:
permissions:
id-token: write
actions: read
checks: read
deployments: read
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
if: github.repository == 'aws-powertools/powertools-lambda-dotnet'
concurrency:
group: analytics
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ on:
workflow_dispatch: {}

permissions:
id-token: write
contents: write
pages: write
contents: read

jobs:
docs:
permissions:
id-token: write
contents: write
# Force Github action to run only a single job at a time (based on the group name)
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages`
concurrency:
Expand Down Expand Up @@ -46,6 +47,9 @@ jobs:
dist \
s3://${{ secrets.AWS_DOCS_BUCKET }}/lambda-dotnet/
apidocs:
permissions:
id-token: write
contents: write
# Force Github action to run only a single job at a time (based on the group name)
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages`
concurrency:
Expand Down
27 changes: 18 additions & 9 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ concurrency:
group: e2e

permissions:
id-token: write
contents: read

jobs:
deploy-stack:
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -45,17 +46,19 @@ jobs:
dotnet-version: '8.x'

- name: Install CDK
run: npm install -g aws-cdk
run: npm install

- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Deploy Stack
run: |
cd libraries/tests/e2e/infra
cdk deploy --all --require-approval never
npx cdk deploy --all --require-approval never

deploy-aot-stack:
permissions:
id-token: write
strategy:
matrix:
os: [ubuntu-24.04-arm, ubuntu-latest]
Expand All @@ -82,17 +85,19 @@ jobs:
dotnet-version: '8.x'

- name: Install CDK
run: npm install -g aws-cdk
run: npm install

- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Deploy AOT Stack
run: |
cd libraries/tests/e2e/infra-aot
cdk deploy --all -c architecture=${{ matrix.arch }} --require-approval never
npx cdk deploy --all -c architecture=${{ matrix.arch }} --require-approval never

run-tests:
permissions:
id-token: write
strategy:
matrix:
utility: [core, idempotency]
Expand Down Expand Up @@ -126,6 +131,8 @@ jobs:
dotnet test --filter Category=AOT

destroy-stack:
permissions:
id-token: write
runs-on: ubuntu-latest
needs: run-tests
if: always()
Expand All @@ -141,17 +148,19 @@ jobs:
mask-aws-account-id: true

- name: Install CDK
run: npm install -g aws-cdk
run: npm install

- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Destroy Stack
run: |
cd libraries/tests/e2e/infra
cdk destroy --all --force
npx cdk destroy --all --force

destroy-aot-stack:
permissions:
id-token: write
strategy:
matrix:
os: [ubuntu-24.04-arm, ubuntu-latest]
Expand All @@ -175,13 +184,13 @@ jobs:
mask-aws-account-id: true

- name: Install CDK
run: npm install -g aws-cdk
run: npm install

- name: Install AWS Lambda .NET CLI Tools
run: dotnet tool install -g Amazon.Lambda.Tools

- name: Destroy arm64 AOT Stack
run: |
cd libraries/tests/e2e/infra-aot
cdk destroy --all -c architecture=${{ matrix.arch }} --force
npox cdk destroy --all -c architecture=${{ matrix.arch }} --force

7 changes: 7 additions & 0 deletions .github/workflows/label_pr_on_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ on:
types:
- completed

permissions:
contents: read

jobs:
get_pr_details:
permissions:
id-token: write
# Guardrails to only ever run if PR recording workflow was indeed
# run in a PR event and ran successfully
if: ${{ github.event.workflow_run.conclusion == 'success' }}
Expand All @@ -18,6 +23,8 @@ jobs:
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
label_pr:
permissions:
id-token: write
needs: get_pr_details
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/on_label_added.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ on:
types:
- completed

permissions:
contents: read

jobs:
get_pr_details:
permissions:
id-token: write
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
Expand All @@ -22,6 +27,7 @@ jobs:
permissions:
issues: write
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# Maintenance: Persist state per PR as an artifact to avoid spam on label add
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/on_merged_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ on:
types:
- completed

permissions:
contents: read

jobs:
get_pr_details:
permissions:
id-token: write
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
Expand All @@ -16,6 +21,8 @@ jobs:
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
release_label_on_merge:
permissions:
id-token: write
needs: get_pr_details
runs-on: ubuntu-latest
if: needs.get_pr_details.outputs.prIsMerged == 'true'
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/on_opened_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ on:
types:
- completed

permissions:
contents: read

jobs:
get_pr_details:
permissions:
id-token: write
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
Expand All @@ -16,6 +21,8 @@ jobs:
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
check_related_issue:
permissions:
id-token: write
needs: get_pr_details
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/rebuild_latest_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
description: "Latest PyPi published version to rebuild latest docs for, e.g. 2.0.0"
default: "2.0.0"
required: true

permissions:
contents: read

jobs:
changelog:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/record_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types: [opened, edited, closed]


permissions:
contents: read

jobs:
record_pr:
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ on:
- develop
workflow_dispatch:

permissions:
contents: read

jobs:
update_release_draft:
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v5.20.1
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/reusable_export_pr_details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ on:
description: "Whether PR is merged"
value: ${{ jobs.export_pr_details.outputs.prIsMerged }}

permissions:
contents: read

jobs:
export_pr_details:
permissions:
id-token: write
# see https://github.com/aws-powertools/powertools-lambda-python/issues/1349
if: inputs.workflow_origin == 'aws-powertools/powertools-lambda-dotnet'
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/reusable_publish_changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ on:
workflow_call:

permissions:
contents: write
contents: read

env:
BRANCH: develop

jobs:
publish_changelog:
permissions:
contents: write
# Force Github action to run only a single job at a time (based on the group name)
# This is to prevent race-condition and inconsistencies with changelog push
concurrency:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/reusable_publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ on:
type: boolean

permissions:
id-token: write
contents: write
pages: write
contents: read

jobs:
publish_docs:
permissions:
id-token: write
contents: write
# Force Github action to run only a single job at a time (based on the group name)
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages`
concurrency:
Expand Down Expand Up @@ -80,6 +81,9 @@ jobs:


apidocs:
permissions:
id-token: write
contents: write
# Force Github action to run only a single job at a time (based on the group name)
# This is to prevent "race-condition" in publishing a new version of doc to `gh-pages`
concurrency:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/secure_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
paths:
- ".github/workflows/**"

permissions:
contents: read

jobs:
enforce_pinned_workflows:
name: Harden Security
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ deploy/**
.vs/
.aws-sam

node_modules/*

examples/SimpleLambda/.aws-sam
examples/SimpleLambda/samconfig.toml

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WORKDIR $FUNCTION_DIR/examples/SimpleLambda/src/HelloWorld/
RUN if [ "$SAM_BUILD_MODE" = "debug" ]; then dotnet lambda package --configuration Debug; else dotnet lambda package --configuration Release; fi
RUN if [ "$SAM_BUILD_MODE" = "debug" ]; then cp -r /bin/Debug/net6.0/publish/* /build/build_artifacts; else cp -r bin/Release/net6.0/publish/* /build/build_artifacts; fi

FROM public.ecr.aws/lambda/dotnet:6
FROM public.ecr.aws/lambda/dotnet@sha256:ec61a7f638e2a0c86d75204117cc7710bcdc70222ffc777e3fc1458287b09834

COPY --from=build-image /build/build_artifacts/ /var/task/
# Command can be overwritten by providing a different command in the template directly.
Expand Down
Loading