-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add token revocation several places.
This adds a method to perform token revocation mirroring what Jason did in the action. This calls that method from the new prober, and in Octo STS itself where it creates a token for looking up the trust policy (not what it hands back to the user). Fixes: #61 Signed-off-by: Matt Moore <mattmoor@chainguard.dev>
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 Chainguard, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package octosts | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// Revoke revokes a security token. | ||
func Revoke(ctx context.Context, tok string) error { | ||
req, err := http.NewRequest(http.MethodDelete, "https://api.github.com/installation/token", nil) | ||
if err != nil { | ||
return fmt.Errorf("creating request: %w", err) | ||
} | ||
req = req.WithContext(ctx) | ||
req.Header.Add("Authorization", "Bearer "+tok) | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return fmt.Errorf("making request: %w", err) | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusNoContent { | ||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode) | ||
} | ||
|
||
// The token was revoked! | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters