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 NamespaceStore to the namespace branch #896

Open
wants to merge 3 commits into
base: namespaces
Choose a base branch
from

Conversation

tabilet
Copy link

@tabilet tabilet commented Jan 15, 2025

This is the first step toward the full namespace feature in Openbao, described in RFC - Add Namespace Support to OpenBao #787

Changes:

  • vault/namespace_oss.go, which describes the NamespaceStore struct, is renamed to vault/namespace_openbao.go
  • Changes in http/util.go to pass namespace string in request context.
  • API-based testing cases using backend file are placed in command/ns_openbao/file
  • More changes are needed to support plugins, mounts and auths in namespace.

To run the tests:

$ ./bin/bao server -config=./command/ns_openbao/file.hcl

go to another terminal and run

$ cd command/ns_openbao/file/

$ go test ./...

}

func (c *Core) ListNamespaces(includePath bool) []*namespace.Namespace {
return []*namespace.Namespace{namespace.RootNamespace}
Copy link
Contributor

Choose a reason for hiding this comment

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

Function should return all namespaces, not only root namespace

return namespaceByID(ctx, nsID, c)
}

func (c *Core) ListNamespaces(includePath bool) []*namespace.Namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

Function should remain in namespaces_oss.go with copyright HashiCorp

"github.com/openbao/openbao/sdk/v2/logical"
)

func (c *Core) NamespaceByID(ctx context.Context, nsID string) (*namespace.Namespace, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Function should remain in namespaces_oss.go with copyright HashiCorp

@@ -0,0 +1,475 @@
// Copyright (c) HashiCorp, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

New files should have copyright OpenBao, right?

Copy link
Member

Choose a reason for hiding this comment

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

Correct:

Suggested change
// Copyright (c) HashiCorp, Inc.
// Copyright (c) 2025 OpenBao a Series of LF Projects, LLC

)

func (c *Core) NamespaceByID(ctx context.Context, nsID string) (*namespace.Namespace, error) {
return namespaceByID(ctx, nsID, c)
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementation of namespaceByID in namespaces.go should be fixed (returns root namespace or error)

Copy link
Member

@cipherboy cipherboy left a comment

Choose a reason for hiding this comment

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

First round of comments!

"identity",
}

func (b *SystemBackend) namespacePaths() []*framework.Path {
Copy link
Member

Choose a reason for hiding this comment

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

I think these would best go in logical_system_namespaces.go to separate them from the store implementation and for consistency with the existing code layout.

Copy link
Contributor

@klaus-sap klaus-sap Jan 22, 2025

Choose a reason for hiding this comment

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

Shouldn't we rename the file namespaces_openbao.go to namespaces_store.go? The suffix openbao does not indicate the purpose of the file

Copy link
Member

Choose a reason for hiding this comment

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

@klaus-sap I agree, but just NamespaceStore (the struct) should be in that new file named namespace_store.go; the API handlers should follow the naming convention of that subsystem (and thus be logical_system_namespaces). My 2c.

Copy link
Contributor

@klaus-sap klaus-sap Jan 22, 2025

Choose a reason for hiding this comment

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

@cipherboy I agree. The API handlers should be in logical_system, but the struct and functions like NewNamespaceStore, setupNamespaceStore, teardownNamespaceStore, SetNamespace, GetNamespace, ListNamespaces, DeleteNamespace should be in namespace_store.go (in the same way as in policy_store.go)

}

// handleNamespaceSet handles the "/sys/namespaces/<path>" endpoint to set a namespace
func (b *SystemBackend) handleNamespacesSet() framework.OperationFunc {
Copy link
Member

Choose a reason for hiding this comment

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

Handlers as well.

@@ -21,7 +22,88 @@ import (
)

var (
restrictedAPIs = []string{
"sys/activation-flags/secrets-sync/activate",
Copy link
Member

Choose a reason for hiding this comment

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

This path does not exist in OpenBao:

Suggested change
"sys/activation-flags/secrets-sync/activate",

"sys/audit",
"sys/audit-hash",
"sys/config/cors",
"sys/config/group-policy-application",
Copy link
Member

@cipherboy cipherboy Jan 22, 2025

Choose a reason for hiding this comment

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

As above:

Suggested change
"sys/config/group-policy-application",

Copy link
Contributor

@klaus-sap klaus-sap Jan 22, 2025

Choose a reason for hiding this comment

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

What is the suggested change? :-)

Copy link
Member

Choose a reason for hiding this comment

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

@klaus-sap Ah, ty, looks like that one didn't apply. I've fixed it (remove this line).

"sys/config/state",
"sys/config/ui",
"sys/decode-token",
"sys/experiments",
Copy link
Member

Choose a reason for hiding this comment

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

As above:

Suggested change
"sys/experiments",

Comment on lines +75 to +78
"/sys/replication/dr/primary/",
"/sys/replication/dr/secondary/",
"/sys/replication/performance/primary/",
"/sys/replication/performance/secondary/",
Copy link
Member

Choose a reason for hiding this comment

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

These will likely never be in OpenBao:

Suggested change
"/sys/replication/dr/primary/",
"/sys/replication/dr/secondary/",
"/sys/replication/performance/primary/",
"/sys/replication/performance/secondary/",

@@ -0,0 +1,475 @@
// Copyright (c) HashiCorp, Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Correct:

Suggested change
// Copyright (c) HashiCorp, Inc.
// Copyright (c) 2025 OpenBao a Series of LF Projects, LLC


// NewNamespaceStore creates a new NamespaceStore that is backed
// using a given view. It used used to durable store and manage named namespace.
func NewNamespaceStore(ctx context.Context, core *Core, baseView BarrierView, system logical.SystemView, logger hclog.Logger) (*NamespaceStore, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func NewNamespaceStore(ctx context.Context, core *Core, baseView BarrierView, system logical.SystemView, logger hclog.Logger) (*NamespaceStore, error) {
func NewNamespaceStore(ctx context.Context, core *Core, baseView BarrierView, logger hclog.Logger) (*NamespaceStore, error) {

SystemView is unused and I don't think it has a purpose in this code.

Copy link
Member

Choose a reason for hiding this comment

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

This has ramifications elsewhere.

return nil
}

func (ps *NamespaceStore) invalidate(ctx context.Context, path string) error {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (ps *NamespaceStore) invalidate(ctx context.Context, path string) error {
func (ns *NamespaceStore) invalidate(ctx context.Context, path string) error {

How about ns rather than ps for NamespaceStore?

if err != nil {
return nil, fmt.Errorf("could not parse namespace from http context: %w", err)
}
//ns, err := namespace.FromContext(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Not quite sure I understand this? Don't we want to be grabbing the namespace?

}

// PatchNamespace is used to update the given namespace
func (ps *NamespaceStore) PatchNamespace(ctx context.Context, path string, meta map[string]string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants