Skip to content

Commit

Permalink
Auth Improvements (micro#1195)
Browse files Browse the repository at this point in the history
* Exclude Stats & Trace from Auth

* Update Excluded Endpoints Format

* Tweak Implementation
  • Loading branch information
ben-toogood committed Feb 13, 2020
1 parent ea70711 commit e080ecb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ var (
&cli.StringSliceFlag{
Name: "auth_exclude",
EnvVars: []string{"MICRO_AUTH_EXCLUDE"},
Usage: "Comma-separated list of endpoints excluded from authentication",
Usage: "Comma-separated list of endpoints excluded from authentication, e.g. Users.ListUsers",
},
}

Expand Down
16 changes: 6 additions & 10 deletions util/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,14 @@ func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
// get the auth.Auth interface
a := fn()

// Extract endpoint and remove service name prefix
// (e.g. Platform.ListServices => ListServices)
var endpoint string
if ec := strings.Split(req.Endpoint(), "."); len(ec) == 2 {
endpoint = ec[1]
// Check for debug endpoints which should be excluded from auth
if strings.HasPrefix(req.Endpoint(), "Debug.") {
return h(ctx, req, rsp)
}

// Check for endpoints excluded from auth. If the endpoint
// matches, execute the handler and return
excludes := append(a.Options().Excludes, "Stats", "Trace")
for _, e := range excludes {
if e == endpoint {
// Exclude any user excluded endpoints
for _, e := range a.Options().Excludes {
if e == req.Endpoint() {
return h(ctx, req, rsp)
}
}
Expand Down

0 comments on commit e080ecb

Please sign in to comment.