Skip to content

Commit 45aa16c

Browse files
committed
Add RequireFipsCryptography support for PS256 auth
* legacy auth is still working at the moment, use new if using broker service or the unseen feature flag is on
1 parent ebd9dcf commit 45aa16c

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

protocol/task_agent.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ type TaskAgents struct {
116116
func (taskAgent *TaskAgent) Authorize(c *http.Client, key interface{}) (*VssOAuthTokenResponse, error) {
117117
tokenresp := &VssOAuthTokenResponse{}
118118
now := time.Now().UTC().Add(-30 * time.Second)
119-
token2 := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.StandardClaims{
119+
var method jwt.SigningMethod = jwt.SigningMethodRS256
120+
requireFipsCryptography, hasRequireFipsCryptography := taskAgent.Properties.LookupBool("RequireFipsCryptography")
121+
serverV2URL, _ := taskAgent.Properties.LookupString("ServerUrlV2")
122+
if requireFipsCryptography && hasRequireFipsCryptography || serverV2URL != "" {
123+
method = jwt.SigningMethodPS256
124+
}
125+
token2 := jwt.NewWithClaims(method, jwt.StandardClaims{
120126
Subject: taskAgent.Authorization.ClientID,
121127
Issuer: taskAgent.Authorization.ClientID,
122128
Id: uuid.New().String(),

runnerconfiguration/compat/actions_runner_compat.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ type DotnetCredentials struct {
4545
}
4646

4747
type DotnetCredentialsData struct {
48-
ClientID string `json:"ClientId"`
49-
AuthorizationURL string `json:"AuthorizationUrl"`
48+
ClientID string `json:"ClientId"`
49+
AuthorizationURL string `json:"AuthorizationUrl"`
50+
RequireFipsCryptography bool `json:"RequireFipsCryptography"`
5051
}
5152

5253
func BytesToBigInt(bytes []byte) *big.Int {
@@ -159,6 +160,12 @@ func ToRunnerInstance(fileAccess ConfigFileAccess) (*runnerconfiguration.RunnerI
159160
Value: agent.UseV2Flow,
160161
}
161162
}
163+
if credentials.Data.RequireFipsCryptography {
164+
props["RequireFipsCryptography"] = protocol.PropertyValue{
165+
Type: "System.Boolean",
166+
Value: credentials.Data.RequireFipsCryptography,
167+
}
168+
}
162169

163170
return &runnerconfiguration.RunnerInstance{
164171
PoolID: poolID,
@@ -208,11 +215,15 @@ func FromRunnerInstance(instance *runnerconfiguration.RunnerInstance, fileAccess
208215
if agent.WorkFolder == "" {
209216
agent.WorkFolder = "_work"
210217
}
218+
requireFipsCryptography, hasRequireFipsCryptography := instance.Agent.Properties.LookupBool("RequireFipsCryptography")
211219
credentials := &DotnetCredentials{
212220
Scheme: "OAuth",
213221
Data: DotnetCredentialsData{
214222
ClientID: instance.Agent.Authorization.ClientID,
215223
AuthorizationURL: instance.Agent.Authorization.AuthorizationURL,
224+
// serverV2URL != "" means recent GitHub Server that requires recent actions/runner
225+
// that has received this bugfix https://github.com/actions/runner/pull/3789
226+
RequireFipsCryptography: requireFipsCryptography && hasRequireFipsCryptography || serverV2URL != "",
216227
},
217228
}
218229
if err := fileAccess.Write(".runner", agent); err != nil {

0 commit comments

Comments
 (0)