Skip to content

Commit

Permalink
backport of commit ef765d3 (hashicorp#19137)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
  • Loading branch information
hc-github-team-secure-vault-core and tomhjp committed Feb 10, 2023
1 parent af66575 commit cfb8f08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions http/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func handleEventsSubscribe(core *vault.Core) http.Handler {
}

prefix := "/v1/sys/events/subscribe/"
if ns.ID != "root" {
prefix = fmt.Sprintf("/v1/%s/sys/events/subscribe/", ns.Path)
if ns.ID != namespace.RootNamespaceID {
prefix = fmt.Sprintf("/v1/%ssys/events/subscribe/", ns.Path)
}
eventTypeStr := strings.TrimSpace(strings.TrimPrefix(r.URL.Path, prefix))
if eventTypeStr == "" {
Expand Down
5 changes: 0 additions & 5 deletions http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-sockaddr"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/vault/helper/experiments"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/internalshared/configutil"
"github.com/hashicorp/vault/sdk/helper/consts"
Expand Down Expand Up @@ -177,10 +176,6 @@ func handler(props *vault.HandlerProperties) http.Handler {
mux.Handle("/v1/sys/storage/raft/join", handleSysRaftJoin(core))
mux.Handle("/v1/sys/internal/ui/feature-flags", handleSysInternalFeatureFlags(core))

if core.IsExperimentEnabled(experiments.VaultExperimentEventsAlpha1) {
mux.Handle("/v1/sys/events/subscribe/", handleEventsSubscribe(core))
}

for _, path := range injectDataIntoTopRoutes {
mux.Handle(path, handleRequestForwarding(core, handleLogicalWithInjector(core)))
}
Expand Down
19 changes: 19 additions & 0 deletions http/logical.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

uuid "github.com/hashicorp/go-uuid"
"github.com/hashicorp/vault/helper/experiments"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/sdk/logical"
Expand Down Expand Up @@ -346,6 +347,24 @@ func handleLogicalInternal(core *vault.Core, injectDataIntoTopLevel bool, noForw
return
}

// Websockets need to be handled at HTTP layer instead of logical requests.
if core.IsExperimentEnabled(experiments.VaultExperimentEventsAlpha1) {
ns, err := namespace.FromContext(r.Context())
if err != nil {
respondError(w, http.StatusInternalServerError, err)
return
}
nsPath := ns.Path
if ns.ID == namespace.RootNamespaceID {
nsPath = ""
}
if strings.HasPrefix(r.URL.Path, fmt.Sprintf("/v1/%ssys/events/subscribe/", nsPath)) {
handler := handleEventsSubscribe(core)
handler.ServeHTTP(w, r)
return
}
}

// Make the internal request. We attach the connection info
// as well in case this is an authentication request that requires
// it. Vault core handles stripping this if we need to. This also
Expand Down

0 comments on commit cfb8f08

Please sign in to comment.