-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Vanta provider support (#11)
* Removed debug * Removed debug * Added invalidation route * Inital roll out of added functionality for vanta * Undoing local dev changes * Totally minor doc update * Minor tweak to (hopefully) keep state checking stable until replaced * One more tidy-up * Another unchecked split * Cleanup more stale debug comments * Sloppy cleanup is sloppy * allow oauth config to specify params to forward on auth request * move vanta-specific logic to its own package * Fix botched conflict resolution --------- Co-authored-by: btoews <[email protected]>
- Loading branch information
Showing
7 changed files
with
174 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/ | ||
|
||
name: Fly Deploy | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
deploy: | ||
name: Deploy app | ||
runs-on: ubuntu-latest | ||
concurrency: deploy-group # optional: ensure only one action runs at a time | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: superfly/flyctl-actions/setup-flyctl@master | ||
- run: flyctl deploy --remote-only | ||
env: | ||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |
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
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
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,110 @@ | ||
package vanta | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/superfly/ssokenizer" | ||
"github.com/superfly/ssokenizer/oauth2" | ||
"github.com/superfly/tokenizer" | ||
xoauth2 "golang.org/x/oauth2" | ||
) | ||
|
||
const ( | ||
invalidatePath = "/invalidate" | ||
invalidateURL = "https://api.vanta.com/v1/oauth/token/suspend" | ||
) | ||
|
||
type Config oauth2.Config | ||
|
||
func (c Config) Register(sealKey string, auth tokenizer.AuthConfig) (http.Handler, error) { | ||
handler, err := oauth2.Config(c).Register(sealKey, auth) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if strings.TrimSuffix(r.URL.Path, "/") != invalidatePath { | ||
handler.ServeHTTP(w, r) | ||
return | ||
} | ||
|
||
var ( | ||
ctx = r.Context() | ||
log = ssokenizer.GetLog(r) | ||
) | ||
|
||
accessToken, ok := strings.CutPrefix(r.Header.Get("Authorization"), "Bearer ") | ||
if !ok { | ||
log.WithField("status", http.StatusUnauthorized). | ||
Info("invalidate: missing token") | ||
|
||
w.WriteHeader(http.StatusUnauthorized) | ||
return | ||
} | ||
|
||
tok, err := c.TokenSource(ctx, &xoauth2.Token{AccessToken: accessToken}).Token() | ||
if err != nil { | ||
log.WithField("status", http.StatusForbidden). | ||
WithError(err). | ||
Info("invalidate: failed to get token") | ||
|
||
w.WriteHeader(http.StatusForbidden) | ||
return | ||
} | ||
|
||
if typ := tok.Type(); typ != "Bearer" { | ||
log.WithField("status", http.StatusForbidden). | ||
WithField("type", typ). | ||
WithError(err). | ||
Info("invalidate: bad token type") | ||
|
||
w.WriteHeader(http.StatusForbidden) | ||
return | ||
} | ||
|
||
body, err := json.Marshal(map[string]string{ | ||
"token": tok.AccessToken, | ||
"client_id": c.ClientID, | ||
"client_secret": c.ClientSecret, | ||
}) | ||
if err != nil { | ||
log.WithField("status", http.StatusInternalServerError). | ||
WithError(err). | ||
Info("invalidate: marshal json") | ||
|
||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, invalidateURL, bytes.NewBuffer(body)) | ||
if err != nil { | ||
log.WithField("status", http.StatusInternalServerError). | ||
WithError(err). | ||
Info("invalidate: make request") | ||
|
||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
req.Header.Set("Content-Type", "application/json") | ||
client := http.Client{Timeout: 10 * time.Second} | ||
|
||
resp, err := client.Do(req) | ||
if err != nil { | ||
log.WithField("status", http.StatusServiceUnavailable). | ||
WithError(err). | ||
Info("invalidate: send request") | ||
|
||
w.WriteHeader(http.StatusServiceUnavailable) | ||
return | ||
} | ||
|
||
log.WithField("status", resp.Status). | ||
Info("invalidate: success") | ||
}), nil | ||
|
||
} |