Skip to content

Commit 2dc0bde

Browse files
edmundmillerclaude
andauthored
Add GitHub org token for platform (#175)
* feat: add GitHub fine-grained credential integration for Seqera Platform - Create new github_credentials integration module for Seqera Platform - Add support for fine-grained GitHub tokens to avoid API rate limits - Update configuration to include PLATFORM_GITHUB_ORG_TOKEN from ESC - Integrate credential creation into main infrastructure deployment - Export GitHub credential information for monitoring and reference - Use protected resource to prevent accidental credential deletion This enables Seqera Platform to pull pipeline repositories without hitting GitHub rate limits by using fine-grained personal access tokens with scoped access to nf-core repositories. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix: add base_url to scope GitHub credential to nf-core organization - Add base_url="https://github.com/nf-core/" to GitHub credential - Prevents conflicts with existing generic GitHub credentials - Scopes fine-grained token specifically to nf-core repositories - Resolves "Credentials already exist within workspace" error 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * feat: add base_url to GitHub credential export information - Include base_url in GitHub credential export for monitoring - Shows credential is scoped to https://github.com/nf-core/ - Improves visibility of credential configuration - Helps with troubleshooting and documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 218e093 commit 2dc0bde

File tree

4 files changed

+130
-3
lines changed

4 files changed

+130
-3
lines changed

pulumi/AWSMegatests/__main__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
deploy_seqera_environments_terraform,
1616
get_compute_environment_ids_terraform,
1717
)
18-
from src.integrations import create_github_resources
18+
from src.integrations import create_github_resources, create_github_credential
1919
from src.integrations.workspace_participants_command import (
2020
create_individual_member_commands,
2121
)
@@ -35,6 +35,14 @@ def main():
3535
# Create Seqera provider early for credential upload
3636
seqera_provider = create_seqera_provider(config)
3737

38+
# Step 3.5: Create GitHub fine-grained credential in Seqera Platform
39+
# This allows Platform to pull pipeline repositories without hitting GitHub rate limits
40+
github_credential, github_credential_id = create_github_credential(
41+
seqera_provider=seqera_provider,
42+
workspace_id=int(config["tower_workspace_id"]),
43+
github_token=config.get("platform_github_org_token", ""),
44+
)
45+
3846
# Step 4: Set up S3 infrastructure
3947
s3_resources = create_s3_infrastructure(aws_provider)
4048
nf_core_awsmegatests_bucket = s3_resources["bucket"]
@@ -136,6 +144,20 @@ def main():
136144
pulumi.export("workspace_id", config["tower_workspace_id"])
137145
pulumi.export("deployment_method", deployment_method)
138146

147+
# Export GitHub credential information
148+
pulumi.export(
149+
"github_credential",
150+
{
151+
"credential_id": github_credential_id,
152+
"credential_name": "nf-core-github-finegrained",
153+
"description": "Fine-grained GitHub token to avoid rate limits when Platform pulls pipeline repositories",
154+
"provider_type": "github",
155+
"base_url": "https://github.com/nf-core/",
156+
"workspace_id": config["tower_workspace_id"],
157+
"purpose": "Prevents GitHub API rate limiting during pipeline repository access",
158+
},
159+
)
160+
139161
# Export Terraform provider resources
140162
pulumi.export(
141163
"terraform_resources",

pulumi/AWSMegatests/src/config/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class InfrastructureConfig:
2020
Attributes:
2121
tower_access_token: Seqera Platform access token
2222
tower_workspace_id: Seqera Platform workspace ID
23-
github_token: GitHub personal access token
23+
github_token: GitHub personal access token (classic)
24+
platform_github_org_token: GitHub fine-grained token to avoid rate limits when pulling pipelines
2425
"""
2526

2627
tower_access_token: Optional[str]
2728
tower_workspace_id: str
2829
github_token: Optional[str]
30+
platform_github_org_token: Optional[str]
2931

3032
def validate(self) -> None:
3133
"""Validate configuration values.
@@ -98,6 +100,7 @@ def get_configuration() -> Dict[str, Any]:
98100
tower_access_token=os.environ.get("TOWER_ACCESS_TOKEN"),
99101
tower_workspace_id=workspace_id or "",
100102
github_token=os.environ.get("GITHUB_TOKEN"),
103+
platform_github_org_token=os.environ.get("PLATFORM_GITHUB_ORG_TOKEN"),
101104
)
102105

103106
# Validate configuration
@@ -108,6 +111,7 @@ def get_configuration() -> Dict[str, Any]:
108111
"tower_access_token": config.tower_access_token,
109112
"tower_workspace_id": config.tower_workspace_id,
110113
"github_token": config.github_token,
114+
"platform_github_org_token": config.platform_github_org_token,
111115
# AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN)
112116
# are automatically handled by ESC and picked up by the AWS provider
113117
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
"""Third-party integrations for AWS Megatests."""
22

33
from .github import create_github_resources
4+
from .github_credentials import create_github_credential, get_github_credential_config
45

5-
__all__ = ["create_github_resources"]
6+
__all__ = [
7+
"create_github_resources",
8+
"create_github_credential",
9+
"get_github_credential_config",
10+
]
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""GitHub credentials integration for Seqera Platform."""
2+
3+
import pulumi
4+
import pulumi_seqera as seqera
5+
from typing import Dict, Tuple
6+
7+
8+
class GitHubCredentialError(Exception):
9+
"""Exception raised when GitHub credential creation fails."""
10+
11+
pass
12+
13+
14+
def create_github_credential(
15+
seqera_provider: seqera.Provider,
16+
workspace_id: int,
17+
github_token: str,
18+
github_username: str = "nf-core-bot",
19+
credential_name: str = "nf-core-github-finegrained",
20+
) -> Tuple[seqera.Credential, str]:
21+
"""Create a GitHub fine-grained credential in Seqera Platform.
22+
23+
This credential allows Seqera Platform to pull pipeline repositories from GitHub
24+
without hitting GitHub rate limits. The fine-grained token provides secure,
25+
scoped access to nf-core repositories with minimal required permissions.
26+
27+
Args:
28+
seqera_provider: Configured Seqera provider instance
29+
workspace_id: Seqera workspace ID
30+
github_token: Fine-grained GitHub personal access token for repository access
31+
github_username: GitHub username (default: nf-core-bot)
32+
credential_name: Name for the credential in Seqera
33+
34+
Returns:
35+
Tuple of (credential_resource, credential_id)
36+
37+
Raises:
38+
GitHubCredentialError: If credential creation fails
39+
ValueError: If required parameters are missing
40+
"""
41+
# Validate required parameters
42+
if not github_token:
43+
raise ValueError("GitHub token is required")
44+
if not workspace_id:
45+
raise ValueError("Workspace ID is required")
46+
47+
pulumi.log.info(
48+
f"Creating GitHub credential '{credential_name}' in workspace {workspace_id}"
49+
)
50+
51+
try:
52+
# Create GitHub credential using Seqera Terraform provider
53+
github_credential = seqera.Credential(
54+
f"github-credential-{credential_name}",
55+
name=credential_name,
56+
description="Fine-grained GitHub token to avoid rate limits when Platform pulls pipeline repositories",
57+
provider_type="github",
58+
base_url="https://github.com/nf-core/", # Scope to nf-core organization
59+
keys=seqera.CredentialKeysArgs(
60+
github=seqera.CredentialKeysGithubArgs(
61+
username=github_username,
62+
password=github_token, # GitHub tokens go in the password field
63+
)
64+
),
65+
workspace_id=workspace_id,
66+
opts=pulumi.ResourceOptions(
67+
provider=seqera_provider,
68+
protect=True, # Protect credential from accidental deletion
69+
),
70+
)
71+
72+
# Return both the resource and the credential ID for reference
73+
return github_credential, github_credential.id
74+
75+
except Exception as e:
76+
pulumi.log.error(f"Failed to create GitHub credential: {str(e)}")
77+
raise GitHubCredentialError(
78+
f"GitHub credential creation failed: {str(e)}"
79+
) from e
80+
81+
82+
def get_github_credential_config() -> Dict[str, str]:
83+
"""Get configuration for GitHub credential creation.
84+
85+
Returns:
86+
Dict containing configuration values from ESC environment
87+
"""
88+
import os
89+
90+
return {
91+
"github_finegrained_token": os.environ.get("PLATFORM_GITHUB_ORG_TOKEN", ""),
92+
"github_username": os.environ.get("GITHUB_USERNAME", "nf-core-bot"),
93+
"credential_name": os.environ.get(
94+
"GITHUB_CREDENTIAL_NAME", "nf-core-github-finegrained"
95+
),
96+
}

0 commit comments

Comments
 (0)