Skip to content
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
36 changes: 21 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ on:
# Run multiple times a day as the successful cached links are not checked every time.
- cron: "0 */8 * * *"

permissions: {}

jobs:
ci:
if: github.repository == 'rust-lang/rustc-dev-guide'
runs-on: ubuntu-latest
permissions:
contents: write # Required by `git push`
env:
MDBOOK_VERSION: 0.5.2
MDBOOK_LINKCHECK2_VERSION: 0.13.0
Expand All @@ -26,13 +30,14 @@ jobs:
with:
# linkcheck needs the base commit.
fetch-depth: 0
persist-credentials: false

- name: Test CI scripts
run: ci/tests/report-scheduled-linkcheck-failure.sh

- name: Cache binaries
id: mdbook-cache
uses: actions/cache@v4
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
~/.cargo/bin
Expand All @@ -41,7 +46,7 @@ jobs:
- name: Restore cached Linkcheck
if: github.event_name == 'schedule'
id: cache-linkcheck-restore
uses: actions/cache/restore@v4
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: book/linkcheck/cache.json
key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }}
Expand All @@ -57,9 +62,9 @@ jobs:
- name: Install Dependencies
if: steps.mdbook-cache.outputs.cache-hit != 'true'
run: |
cargo install --locked mdbook --version ${{ env.MDBOOK_VERSION }}
cargo install --locked mdbook-linkcheck2 --version ${{ env.MDBOOK_LINKCHECK2_VERSION }}
cargo install --locked mdbook-mermaid --version ${{ env.MDBOOK_MERMAID_VERSION }}
cargo install --locked mdbook --version ${MDBOOK_VERSION}
cargo install --locked mdbook-linkcheck2 --version ${MDBOOK_LINKCHECK2_VERSION}
cargo install --locked mdbook-mermaid --version ${MDBOOK_MERMAID_VERSION}

- name: Check build
run: ENABLE_LINKCHECK=1 mdbook build
Expand All @@ -73,24 +78,24 @@ jobs:
- name: Save cached Linkcheck
id: cache-linkcheck-save
if: ${{ !cancelled() && github.event_name == 'schedule' }}
uses: actions/cache/save@v4
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: book/linkcheck/cache.json
key: linkcheck--${{ env.MDBOOK_LINKCHECK2_VERSION }}--${{ github.run_id }}

- name: Deploy to gh-pages
if: github.event_name == 'push'
run: |
touch "${{ env.DEPLOY_DIR }}/.nojekyll"
cp CNAME "${{ env.DEPLOY_DIR }}"
cd "${{ env.DEPLOY_DIR }}"
touch "${DEPLOY_DIR}/.nojekyll"
cp CNAME "${DEPLOY_DIR}"
cd "${DEPLOY_DIR}"
rm -rf .git
git init
git config user.name "Deploy from CI"
git config user.email ""
git add .
git commit -m "Deploy ${GITHUB_SHA} to gh-pages"
git push --quiet -f "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change? Is GITHUB_TOKEN even passed as an environment variable by default?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why this change?

template-injection lint. Even when not necessarily dangerous, zizmor considers template expansions a code smell.

Is GITHUB_TOKEN even passed as an environment variable by default?

I don't think so, but in this case, it was already explicitly put into the environment:

jobs:
ci:
if: github.repository == 'rust-lang/rustc-dev-guide'
runs-on: ubuntu-latest
env:
MDBOOK_VERSION: 0.5.2
MDBOOK_LINKCHECK2_VERSION: 0.13.0
MDBOOK_MERMAID_VERSION: 0.17.0
MDBOOK_OUTPUT__LINKCHECK__FOLLOW_WEB_LINKS: ${{ github.event_name != 'pull_request' }}
DEPLOY_DIR: book/html
BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. It seems safer to not put it into the environment and only access it through secrets, but I don't know if there is anything else here that might be reading it.

FWIW, I don't like this lint being applied to things that are clearly safe from expansion attacks, such as secrets.GITHUB_TOKEN.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't know if there is anything else here that might be reading it.

Yeah, that's the tricky part. There's only so much I can do to test these things on my own (I already accidentally used up all my free minutes for this month doing so, it seems... oops!), so I have to try to err on the side of "not breaking infrastructure".

It seems safer to not put it into the environment and only access it through secrets

I think it isn't really meaningfully safer, though I would definitely prefer the scope be reduced (env for a specific step, rather than the entire job). That suffers the same "I don't know what might be using this already" problem, though.

Ideally, the token only grants read permissions/none at all and is not really a concern regardless for public repos. Which I think is the relationship permissions: {} creates? It's a little unclear how that works.

git push --quiet -f "https://x-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages

- name: Check if files comply with semantic line breaks
continue-on-error: true
Expand All @@ -104,11 +109,11 @@ jobs:
if: failure() && github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
issues: write
issues: write # Required to open issues with `gh issue create`
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Open an issue or comment on an existing one
run: ci/report-scheduled-linkcheck-failure.sh
env:
Expand All @@ -120,10 +125,11 @@ jobs:
if: success() && github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
issues: write # Required to close issues with `gh issue close`
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Close issue
run: ci/close-scheduled-linkcheck-issues.sh
env:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/date-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ on:
# Allow manually starting the workflow
workflow_dispatch:

permissions: {}

jobs:
date-check:
if: github.repository == 'rust-lang/rustc-dev-guide'
runs-on: ubuntu-latest

permissions:
Comment thread
Kobzol marked this conversation as resolved.
Resolved
issues: write # Required by `actions/github-script` to open issues
steps:
- name: Checkout repo
uses: actions/checkout@v7
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Ensure Rust is up-to-date
run: |
Expand All @@ -25,7 +30,7 @@ jobs:
run: cargo run --manifest-path ci/date-check/Cargo.toml . > date-check-output.txt

- name: Open issue
uses: actions/github-script@v7
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const fs = require('fs');
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/rustc-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ on:
# Run at 04:00 UTC every Monday
- cron: '0 4 * * 1'

permissions: {}

jobs:
pull:
if: github.repository == 'rust-lang/rustc-dev-guide'
permissions:
contents: write # Required by `josh-sync/rustc-pull` to push to a branch
pull-requests: write # Required by `josh-sync/rustc-pull` to open a PR
# zizmor: ignore[unpinned-uses] We explicitly want to track the main branch.
uses: rust-lang/josh-sync/.github/workflows/rustc-pull.yml@main
with:
github-app-id: ${{ vars.APP_CLIENT_ID }}
Expand Down
Loading