Skip to content

Commit

Permalink
[v17] Fixes unhandled v1 prefixed 'web/config.js' path (#51368)
Browse files Browse the repository at this point in the history
* Fixes bug where /v1/web/config.js wasn't properly handled because of v1 prefix

* Fix lint
  • Loading branch information
kimlisa authored Jan 22, 2025
1 parent 87c5a6b commit 06bde83
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func NewHandler(cfg Config, opts ...HandlerOption) (*APIHandler, error) {
// part[0] is empty space from leading slash "/"
// part[1] is the prefix "v1"
switch pathParts[2] {
case "webapi", "enterprise", "scripts", ".well-known", "workload-identity":
case "webapi", "enterprise", "scripts", ".well-known", "workload-identity", "web":
http.StripPrefix(v1Prefix, h).ServeHTTP(w, r)
return
}
Expand Down Expand Up @@ -1946,7 +1946,7 @@ func setEntitlementsWithLegacyLogic(webCfg *webclient.WebConfig, clusterFeatures
// set default Identity fields to legacy feature value
webCfg.Entitlements[string(entitlements.AccessLists)] = webclient.EntitlementInfo{Enabled: true, Limit: clusterFeatures.GetAccessList().GetCreateLimit()}
webCfg.Entitlements[string(entitlements.AccessMonitoring)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetAccessMonitoring().GetEnabled(), Limit: clusterFeatures.GetAccessMonitoring().GetMaxReportRangeLimit()}
webCfg.Entitlements[string(entitlements.AccessRequests)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetAccessRequests().MonthlyRequestLimit > 0, Limit: clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit()}
webCfg.Entitlements[string(entitlements.AccessRequests)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit() > 0, Limit: clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit()}
webCfg.Entitlements[string(entitlements.DeviceTrust)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetDeviceTrust().GetEnabled(), Limit: clusterFeatures.GetDeviceTrust().GetDevicesUsageLimit()}
// override Identity Package features if Identity is enabled: set true and clear limit
if clusterFeatures.GetIdentityGovernance() {
Expand All @@ -1960,7 +1960,7 @@ func setEntitlementsWithLegacyLogic(webCfg *webclient.WebConfig, clusterFeatures
}

// webCfg.<legacy fields>: set equal to legacy feature value
webCfg.AccessRequests = clusterFeatures.GetAccessRequests().MonthlyRequestLimit > 0
webCfg.AccessRequests = clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit() > 0
webCfg.ExternalAuditStorage = clusterFeatures.GetExternalAuditStorage()
webCfg.HideInaccessibleFeatures = clusterFeatures.GetFeatureHiding()
webCfg.IsIGSEnabled = clusterFeatures.GetIdentityGovernance()
Expand Down
83 changes: 83 additions & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,89 @@ func TestEndpointNotFoundHandling(t *testing.T) {
}
}

func TestKnownWebPathsWithAndWithoutV1Prefix(t *testing.T) {
t.Parallel()
const username = "[email protected]"
// Allow user to create tokens.
roleTokenCRD, err := types.NewRole(services.RoleNameForUser(username), types.RoleSpecV6{
Allow: types.RoleConditions{
Rules: []types.Rule{
types.NewRule(types.KindToken,
[]string{types.VerbCreate}),
},
},
})
require.NoError(t, err)

env := newWebPack(t, 1)
proxy := env.proxies[0]
pack := proxy.authPack(t, username, []types.Role{roleTokenCRD})

res, err := pack.clt.PostJSON(context.Background(), pack.clt.Endpoint("webapi", "token"), types.ProvisionTokenSpecV2{
Roles: types.SystemRoles{types.RoleNode},
})
require.NoError(t, err)

var responseToken nodeJoinToken
err = json.Unmarshal(res.Bytes(), &responseToken)
require.NoError(t, err)

tt := []struct {
name string
endpoint string
}{
{
name: "web path with prefix",
endpoint: "v1/web/config.js",
},
{
name: "web path without prefix",
endpoint: "web/config.js",
},
{
name: "webapi path with prefix",
endpoint: "v1/webapi/spiffe/bundle.json",
},
{
name: "webapi path without prefix",
endpoint: "webapi/spiffe/bundle.json",
},
{
name: ".well-known path with prefix",
endpoint: "v1/.well-known/jwks.json",
},
{
name: ".well-known path without prefix",
endpoint: ".well-known/jwks.json",
},
{
name: "workload-identity path with prefix",
endpoint: "v1/workload-identity/jwt-jwks.json",
},
{
name: "workload-identity path without prefix",
endpoint: "workload-identity/jwt-jwks.json",
},
{
name: "scripts path with prefix",
endpoint: fmt.Sprintf("v1/scripts/%s/install-node.sh", responseToken.ID),
},
{
name: "scripts path without prefix",
endpoint: fmt.Sprintf("scripts/%s/install-node.sh", responseToken.ID),
},
}

for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
_, err := pack.clt.Get(context.Background(), fmt.Sprintf("%s/%s", proxy.web.URL, tc.endpoint), url.Values{})

require.NoError(t, err)
})
}
}

func TestInstallDatabaseScriptGeneration(t *testing.T) {
const username = "[email protected]"

Expand Down

0 comments on commit 06bde83

Please sign in to comment.