Skip to content

Use context for auth access controllers - #140

Merged
stevvooe merged 1 commit into
distribution:masterfrom
jlhawn:137_auth_context
Feb 5, 2015
Merged

stevvooe merged 1 commit into
distribution:masterfrom
jlhawn:137_auth_context

Conversation

@jlhawn

@jlhawn jlhawn commented Feb 4, 2015

Copy link
Copy Markdown

The auth package has been updated to use "golang.org/x/net/context" for
passing information between the application and the auth backend.

AccessControllers should now set a "auth.user" context value to a AuthUser
struct containing a single "Name" field for now with possible, optional, values
in the future.

The "silly" auth backend always sets the name to "silly", while the "token" auth
backend will set the name to match the "subject" claim of the JWT.

closes #137

@jlhawn jlhawn self-assigned this Feb 4, 2015
@stevvooe stevvooe added this to the Registry/Beta milestone Feb 4, 2015
Comment thread auth/auth.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An AccessController no longer authorizes a request; it produces an authorized context.

Should read as follows:

// Authorized returns a non-nil error if the context is granted access and
// ...

@stevvooe

stevvooe commented Feb 4, 2015

Copy link
Copy Markdown
Collaborator

LGTM!

We may want to place the token into the context, along with the access that is available but this is fine for now.

@dmp42

dmp42 commented Feb 4, 2015

Copy link
Copy Markdown
Contributor

It's failing to find the package.

@jlhawn

jlhawn commented Feb 4, 2015

Copy link
Copy Markdown
Author

@dmp42 that's because we're waiting to merge @stevvooe's work on #86 first

@stevvooe

stevvooe commented Feb 4, 2015

Copy link
Copy Markdown
Collaborator

@jlhawn After thinking about it, there is no reason to hold up the merge of this PR waiting on #86.

Go ahead and add golang.org/x/net/context to godep. Add a WithRequest function (I'll move this to a new context package I'm working on):

func WithRequest(ctx context.Context, r *http.Request) context.Context {
    return context.WithValue("http.request", r)
}

Update app.go to push the request into the context before calling authorized (no reason to propagate context all throughout application and request context, yet):

ctx := WithRequest(context.TODO(), r)
if _, err := app.accessController.Authorized(ctx, accessRecords...); err != nil {
...
}
// We don't really need the auth'd context yet

This will be compatible with what I'm doing now and should be equivalent to the current behavior.

The auth package has been updated to use "golang.org/x/net/context" for
passing information between the application and the auth backend.

AccessControllers should now set a "auth.user" context value to a AuthUser
struct containing a single "Name" field for now with possible, optional, values
in the future.

The "silly" auth backend always sets the name to "silly", while the "token" auth
backend will set the name to match the "subject" claim of the JWT.

Docker-DCO-1.1-Signed-off-by: Josh Hawn <[email protected]> (github: jlhawn)
@stevvooe

stevvooe commented Feb 5, 2015

Copy link
Copy Markdown
Collaborator

LGTM!

stevvooe added a commit that referenced this pull request Feb 5, 2015
Use context for auth access controllers
@stevvooe
stevvooe merged commit 9b9ea55 into distribution:master Feb 5, 2015
@stevvooe stevvooe modified the milestones: Registry/2.0.0-beta, Registry/2.0 Mar 31, 2015
thaJeztah pushed a commit to thaJeztah/distribution that referenced this pull request Apr 22, 2021
Use context for auth access controllers
thaJeztah pushed a commit to thaJeztah/distribution that referenced this pull request Jan 19, 2022
Use context for auth access controllers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make User information available via auth package

3 participants