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

Pass identity metadata through to plugins #4967

Merged
merged 1 commit into from
Jul 23, 2018
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
84 changes: 54 additions & 30 deletions logical/identity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion logical/identity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ message Entity {

// Aliases contains thhe alias mappings for the given entity
repeated Alias aliases = 3;

// Metadata represents the custom data tied to this entity
map<string, string> metadata = 4;
}

message Alias {
Expand All @@ -25,5 +28,7 @@ message Alias {

// Name is the identifier of this identity in its authentication source
string name = 3;
}

// Metadata represents the custom data tied to this alias
map<string, string> metadata = 4;
}
16 changes: 15 additions & 1 deletion logical/plugin/grpc_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"reflect"

"github.com/gogo/protobuf/proto"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/logical"
Expand Down Expand Up @@ -170,6 +171,19 @@ func TestSystem_GRPC_entityInfo(t *testing.T) {
sys.EntityVal = &logical.Entity{
ID: "id",
Name: "name",
Metadata: map[string]string{
"foo": "bar",
},
Aliases: []*logical.Alias{
&logical.Alias{
MountType: "logical",
MountAccessor: "accessor",
Name: "name",
Metadata: map[string]string{
"zip": "zap",
},
},
},
}
client, _ := plugin.TestGRPCConn(t, func(s *grpc.Server) {
pb.RegisterSystemViewServer(s, &gRPCSystemViewServer{
Expand All @@ -183,7 +197,7 @@ func TestSystem_GRPC_entityInfo(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if sys.EntityVal.ID != actual.ID || sys.EntityVal.Name != actual.Name {
if !proto.Equal(sys.EntityVal, actual) {
t.Fatalf("expected: %v, got: %v", sys.EntityVal, actual)
}
}
42 changes: 30 additions & 12 deletions vault/dynamic_system_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,40 @@ func (d dynamicSystemView) EntityInfo(entityID string) (*logical.Entity, error)
return nil, nil
}

// Return a subset of the data
ret := &logical.Entity{
ID: entity.ID,
Name: entity.Name,
}

if entity.Metadata != nil {
ret.Metadata = make(map[string]string, len(entity.Metadata))
for k, v := range entity.Metadata {
ret.Metadata[k] = v
}
}

aliases := make([]*logical.Alias, len(entity.Aliases))
for i, alias := range entity.Aliases {
aliases[i] = &logical.Alias{
MountAccessor: alias.MountAccessor,
Name: alias.Name,
for i, a := range entity.Aliases {
alias := &logical.Alias{
MountAccessor: a.MountAccessor,
Name: a.Name,
}
// MountType is not stored with the entity and must be looked up
if mount := d.core.router.validateMountByAccessor(alias.MountAccessor); mount != nil {
aliases[i].MountType = mount.MountType
if mount := d.core.router.validateMountByAccessor(a.MountAccessor); mount != nil {
alias.MountType = mount.MountType
}

if a.Metadata != nil {
alias.Metadata = make(map[string]string, len(a.Metadata))
for k, v := range a.Metadata {
alias.Metadata[k] = v
}
}

aliases[i] = alias
}
ret.Aliases = aliases

// Only returning a subset of the data
return &logical.Entity{
ID: entity.ID,
Name: entity.Name,
Aliases: aliases,
}, nil
return ret, nil
}