Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental whoami api endpoint #9233

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func NewAPI(clusters []*cluster.Cluster, opts Options) *API {

experimentalRouter := router.PathPrefix("/experimental").Subrouter()
experimentalRouter.HandleFunc("/tablet/{tablet}/debug/vars", httpAPI.Adapt(experimental.TabletDebugVarsPassthrough)).Name("API.TabletDebugVarsPassthrough")
experimentalRouter.HandleFunc("/whoami", httpAPI.Adapt(experimental.WhoAmI))

if !opts.HTTPOpts.DisableDebug {
// Due to the way net/http/pprof insists on registering its handlers, we
Expand Down
21 changes: 21 additions & 0 deletions go/vt/vtadmin/http/experimental/whoami.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package experimental

import (
"context"

vtadminhttp "vitess.io/vitess/go/vt/vtadmin/http"
"vitess.io/vitess/go/vt/vtadmin/rbac"
)

// WhoAmI is an experimental route for extracting authenticated Actors from
// the request, to see who is authenticated on the frontend.
func WhoAmI(ctx context.Context, r vtadminhttp.Request, api *vtadminhttp.API) *vtadminhttp.JSONResponse {
data := map[string]interface{}{}
actor, ok := rbac.FromContext(ctx)
data["authenticated"] = ok
if ok {
data["actor"] = actor
}

return vtadminhttp.NewJSONResponse(data, nil)
}
4 changes: 2 additions & 2 deletions go/vt/vtadmin/rbac/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func AuthenticationUnaryInterceptor(authn Authenticator) grpc.UnaryServerInterce
// Actor represents the subject in the "subject action resource" of an
// authorization check. It has a name and many roles.
type Actor struct {
Name string
Roles []string
Name string `json:"name"`
Roles []string `json:"roles"`
}

type actorkey struct{}
Expand Down