Skip to content

Commit

Permalink
Compute the SHA256 of the resulting token and record in event. (#149)
Browse files Browse the repository at this point in the history
This computes the SHA256 of the issued token, which will then be
recorded into BigQuery.

I plan to make an analogous change to `octo-sts-action` (compute and log
the sha256) which will let us associate STS exchanges with particular
actions runs.

Signed-off-by: Matt Moore <[email protected]>
  • Loading branch information
mattmoor authored Mar 8, 2024
1 parent 6812d80 commit 702f579
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions iac/sts_exchange.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "token_sha256",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "error",
"type": "STRING",
Expand Down
1 change: 1 addition & 0 deletions pkg/octosts/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Event struct {
InstallationID int64 `json:"installation_id"`
Scope string `json:"scope"`
Identity string `json:"identity"`
TokenSHA256 string `json:"token_sha256"`
Error string `json:"error,omitempty"`
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/octosts/octosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package octosts

import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -168,6 +170,11 @@ func (s *sts) Exchange(ctx context.Context, request *pboidc.ExchangeRequest) (_
}
return nil, status.Errorf(codes.Internal, "failed to get token: %v", err)
}

// Compute the SHA256 hash of the token and store the hex-encoded value into e.TokenSHA256
hash := sha256.Sum256([]byte(token))
e.TokenSHA256 = hex.EncodeToString(hash[:])

return &pboidc.RawToken{
Token: token,
}, nil
Expand Down

0 comments on commit 702f579

Please sign in to comment.