Skip to content

Fix Android Device Farm OIDC sessions - #3444

Open
geedo0 wants to merge 1 commit into
aws:mainfrom
geedo0:android-ci-fix
Open

Fix Android Device Farm OIDC sessions#3444
geedo0 wants to merge 1 commit into
aws:mainfrom
geedo0:android-ci-fix

Conversation

@geedo0

@geedo0 geedo0 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Context and motivation

Android Device Farm jobs can outlive the one-hour STS role-chaining limit. Their credentials then expire while jobs are queued or running, causing otherwise valid CI runs to fail.

Description of changes

  • Allow the Device Farm role to be assumed directly through GitHub OIDC while preserving its existing chained trust path and repository/workflow restrictions.
  • Add configurable role-session duration to the credential action and skip role chaining when roleName is empty.
  • Configure Android jobs to request a four-hour direct session.
  • Run Android PR validation through pull_request_target for all target branches, while limiting push runs to main and fips-*.

Testing

  • Parsed the workflow and composite-action YAML with yq.
  • Compiled the modified CDK module with py_compile.
  • Synthesized the full CDK application with the pinned dependencies.
  • Inspected the generated production Device Farm role and confirmed both the existing chained trust statement and the new conditioned sts:AssumeRoleWithWebIdentity statement.

No AWS deployment was performed from the development session.

Review considerations

The changes can be merged before the production trust policy lands. Android runs may temporarily fail until the normal CI pipeline deploys the production OIDC stack; those jobs can be rerun afterward. Sessions are static and still fail if queue plus execution time exceeds four hours.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 Security ReviewView Report

Please review before merging.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.02%. Comparing base (e597639) to head (0a51749).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3444   +/-   ##
=======================================
  Coverage   78.02%   78.02%           
=======================================
  Files         699      699           
  Lines      124589   124589           
  Branches    17286    17286           
=======================================
+ Hits        97205    97208    +3     
+ Misses      26516    26514    -2     
+ Partials      868      867    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

devicefarm: DeviceFarmCiProps) -> iam.Role:

device_farm_role = iam.Role(scope, id, role_name=id,
assumed_by=iam.SessionTagsPrincipal(principal),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also set max_session_duration=Duration.hours(4) on the Device Farm role.

Suggested change
max_session_duration=Duration.hours(4),

)
},
}

@justsmth justsmth Aug 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Direct OIDC assumption avoids the one-hour role-chaining limit, but it also bypasses the minimal OIDC role. Restrict this trust path to the one workflow that needs longer-lived Device Farm credentials.

        device_farm_oidc_conditions = {
            **github_actions_oidc_conditions,
            "StringEquals": {
                **github_actions_oidc_conditions["StringEquals"],
                "token.actions.githubusercontent.com:workflow":
                    "android-omnibus",
            },
        }

principals=[
iam.WebIdentityPrincipal(
self.oidc_provider.attr_arn,
github_actions_oidc_conditions,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use device_farm_oidc_conditions instead.

with:
role-to-assume: arn:aws:iam::${{ steps.env.outputs.aws_account_id }}:role/${{ inputs.oidcRole }}
role-session-name: ${{ github.run_id }}-${{ github.run_attempt }}
role-duration-seconds: ${{ inputs.roleDurationSeconds }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: roleDurationSeconds also applies to the chained role, but AWS caps chained sessions at 3600 seconds. Could we document that values above 3600 require roleName: ''?

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.

3 participants