diff --git a/agent/consul/acl.go b/agent/consul/acl.go index 770e1c8e7..dd90d267e 100644 --- a/agent/consul/acl.go +++ b/agent/consul/acl.go @@ -1244,6 +1244,10 @@ func (r *ACLResolver) ResolveTokenToIdentityAndAuthorizer(token string) (structs return identity, acl.NewChainedAuthorizer(chain), nil } +// TODO: rename to AccessorIDFromToken. This method is only used to retrieve the +// ACLIdentity.ID, so we don't need to return a full ACLIdentity. We could +// return a much smaller type (instad of just a string) to allow for changes +// in the future. func (r *ACLResolver) ResolveTokenToIdentity(token string) (structs.ACLIdentity, error) { if !r.ACLsEnabled() { return nil, nil diff --git a/agent/consul/acl_client.go b/agent/consul/acl_client.go index 21106f37c..bc86916ea 100644 --- a/agent/consul/acl_client.go +++ b/agent/consul/acl_client.go @@ -93,6 +93,7 @@ func (c *Client) ResolveTokenToIdentity(token string) (structs.ACLIdentity, erro return c.acls.ResolveTokenToIdentity(token) } +// TODO: Server has an identical implementation, remove duplication func (c *Client) ResolveTokenAndDefaultMeta(token string, entMeta *structs.EnterpriseMeta, authzContext *acl.AuthorizerContext) (acl.Authorizer, error) { identity, authz, err := c.acls.ResolveTokenToIdentityAndAuthorizer(token) if err != nil { diff --git a/agent/consul/acl_server.go b/agent/consul/acl_server.go index 7b753d680..0351c2724 100644 --- a/agent/consul/acl_server.go +++ b/agent/consul/acl_server.go @@ -235,12 +235,11 @@ func (s *Server) ResolveTokenToIdentity(token string) (structs.ACLIdentity, erro return s.acls.ResolveTokenToIdentity(token) } -// ResolveTokenIdentityAndDefaultMeta retrieves an identity and authorizer for the caller, -// and populates the EnterpriseMeta based on the AuthorizerContext. -func (s *Server) ResolveTokenIdentityAndDefaultMeta(token string, entMeta *structs.EnterpriseMeta, authzContext *acl.AuthorizerContext) (structs.ACLIdentity, acl.Authorizer, error) { +// TODO: Client has an identical implementation, remove duplication +func (s *Server) ResolveTokenAndDefaultMeta(token string, entMeta *structs.EnterpriseMeta, authzContext *acl.AuthorizerContext) (acl.Authorizer, error) { identity, authz, err := s.acls.ResolveTokenToIdentityAndAuthorizer(token) if err != nil { - return nil, nil, err + return nil, err } // Default the EnterpriseMeta based on the Tokens meta or actual defaults @@ -254,12 +253,6 @@ func (s *Server) ResolveTokenIdentityAndDefaultMeta(token string, entMeta *struc // Use the meta to fill in the ACL authorization context entMeta.FillAuthzContext(authzContext) - return identity, authz, err -} - -// ResolveTokenAndDefaultMeta passes through to ResolveTokenIdentityAndDefaultMeta, eliding the identity from its response. -func (s *Server) ResolveTokenAndDefaultMeta(token string, entMeta *structs.EnterpriseMeta, authzContext *acl.AuthorizerContext) (acl.Authorizer, error) { - _, authz, err := s.ResolveTokenIdentityAndDefaultMeta(token, entMeta, authzContext) return authz, err } diff --git a/agent/consul/intention_endpoint.go b/agent/consul/intention_endpoint.go index 247ba8560..67f000f5f 100644 --- a/agent/consul/intention_endpoint.go +++ b/agent/consul/intention_endpoint.go @@ -100,15 +100,18 @@ func (s *Intention) Apply(args *structs.IntentionRequest, reply *string) error { } // Get the ACL token for the request for the checks below. - var entMeta structs.EnterpriseMeta - ident, authz, err := s.srv.ResolveTokenIdentityAndDefaultMeta(args.Token, &entMeta, nil) + identity, authz, err := s.srv.acls.ResolveTokenToIdentityAndAuthorizer(args.Token) if err != nil { return err } var accessorID string - if ident != nil { - accessorID = ident.ID() + var entMeta structs.EnterpriseMeta + if identity != nil { + entMeta.Merge(identity.EnterpriseMetadata()) + accessorID = identity.ID() + } else { + entMeta.Merge(structs.DefaultEnterpriseMetaInDefaultPartition()) } var (