Skip to content
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

Add support for short-lived tokens #224

Merged
merged 10 commits into from
May 15, 2024
Merged

Add support for short-lived tokens #224

merged 10 commits into from
May 15, 2024

Conversation

alextu
Copy link
Member

@alextu alextu commented May 14, 2024

The setup-gradle action tries to get a short-lived access token given the passed Develocity access key.
This key can be passed either with the DEVELOCITY_ACCESS_KEY env var or better with a new input develocity-access-key.
If a token can be retrieved, then the DEVELOCITY_ACCESS_KEY env var will be set to the token. Otherwise the DEVELOCITY_ACCESS_KEY will be set to a blank string, to avoid a leak.

@alextu alextu requested review from bigdaz and welandaz May 14, 2024 15:38
Copy link

Job Summary for Gradle

Demo adding Build Scan® comment to PR :: failing-build-with-comment-on-failure
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
kotlin-dsl no-a-real-task 8.7 Build Scan published

Copy link

Job Summary for Gradle

Demo adding Build Scan® comment to PR :: successful-build-with-always-comment
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
kotlin-dsl build 8.7 Build Scan published

Copy link

Job Summary for Gradle

Demo adding Build Scan® comment to PR :: successful-build-with-always-comment
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
kotlin-dsl build 8.7 Build Scan published

Copy link

Job Summary for Gradle

Demo adding Build Scan® comment to PR :: failing-build-with-comment-on-failure
Gradle Root Project Requested Tasks Gradle Version Build Outcome Build Scan®
kotlin-dsl no-a-real-task 8.7 Build Scan published

Copy link
Member

@bigdaz bigdaz left a comment

Choose a reason for hiding this comment

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

Thanks @alextu. I left quite a few comments and change requests.

@@ -0,0 +1,164 @@
import * as httpm from 'typed-rest-client/HttpClient'
Copy link
Member

Choose a reason for hiding this comment

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

The "package" for this file should not be "shortlived-token", but something more general purpose. Let's use "develocity".

Copy link
Member

Choose a reason for hiding this comment

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

Also, for consistency we should name this short-lived-token.

@@ -1,7 +1,8 @@
import * as core from '@actions/core'
Copy link
Member

Choose a reason for hiding this comment

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

This file can be moved into the same "package" as shortlived-token.ts.

working-directory: .github/workflow-samples/no-ge
run: gradle help
- name: Check access key does not leak
run: "[ \"${DEVELOCITY_ACCESS_KEY}\" != \"${{ secrets.DEVELOCITY_ACCESS_KEY }}\" ] || (echo 'DEVELOCITY_ACCESS_KEY has leaked!'; exit 1)"
Copy link
Member

Choose a reason for hiding this comment

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

We need to ensure that the ACCESS KEY isn't leaked to the console here.

script: |
core.setFailed('No Build Scan detected')

inject-develocity-short-lived-token-failed:
Copy link
Member

Choose a reason for hiding this comment

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

What real behaviour are we trying to test here?

Copy link
Member Author

Choose a reason for hiding this comment

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

if requesting a token fails, we want to avoid the passed access key as an env var to be used downstream (and potentially leaked)

script: |
core.setFailed('No Build Scan detected')

inject-develocity-short-lived-token-with-env:
Copy link
Member

Choose a reason for hiding this comment

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

This test already exists in integ-test-inject-develocity. Just need to add the token check.

@@ -0,0 +1,151 @@
name: Test develocity injection
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a separate integration test, let's merge this coverage into the existing inject-develocity test. So we'll be testing develocity injection, and verifying that a short-lived token is used.

develocity-token-expiry:
description: The Develocity short-lived access tokens expiry in hours. Default is 2 hours.
required: false

Copy link
Member

Choose a reason for hiding this comment

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

We need to add the same arguments to the dependency-submission action. These actions share many implementation details, including build-scan publishing.

DEVELOCITY_URL: https://develocity.your-server.com
DEVELOCITY_PLUGIN_VERSION: 3.17
with:
develocity-access-key: ${{ secrets.MY_DEVELOCITY_ACCESS_KEY }}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this will work. The access key needs to be provided to the setup-gradle Step.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh right, my bad


This access key will be used during the action execution to get a short-lived token and set it to the DEVELOCITY_ACCESS_KEY environment variable.

### Short-lived access tokens
Copy link
Member

Choose a reason for hiding this comment

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

The feature to map develocityAccessKey to a short-lived token isn't directly related to Develocity injection. I think we should include develocityAccessKey in our examples for Develocity injection, but this feature will also come into play when the build is configured for Develocity (without injection).

I think we should also consider adding test coverage for this: ensure a sample build that is wired to publish to ge.solutions-team.gradle.com can use short-lived access tokens.

@@ -11,6 +12,34 @@ export function setup(config: BuildScanConfig): void {
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
}
const develocityAccesskeyEnvVar = `DEVELOCITY_ACCESS_KEY`
if (config.getDevelocityAccessKey()) {
try {
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this logic to shortlived-token.ts.

Copy link
Member

@bigdaz bigdaz left a comment

Choose a reason for hiding this comment

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

LGTM

@bigdaz bigdaz merged commit 500e0ee into main May 15, 2024
99 checks passed
@bigdaz bigdaz deleted the atual/short-lived-tokens branch May 15, 2024 22:49
bigdaz pushed a commit that referenced this pull request May 17, 2024
…ars (#225)

Follow up of #224, we now attempt to set both old and new access key env variables to a short lived token.
If a short-lived token cannot be obtained, then:
- DEVELOCITY_ACCESS_KEY is set to an empty string, preventing this from being used.
- GRADLE_ENTERPRISE_ACCESS_KEY is left intact, with a deprecation warning being issued.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants