Skip to content

Commit 56c4311

Browse files
authored
Add feature hide-menu for embedded screens on Operator UI (#1604)
* Add feature hide-menu for embedded screens on Operator UI Signed-off-by: Daniel Valdivia <[email protected]>
1 parent 28dcd19 commit 56c4311

File tree

27 files changed

+381
-166
lines changed

27 files changed

+381
-166
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ WORKDIR /go/src/github.com/minio/console/
2929
ENV CGO_ENABLED=0
3030

3131
COPY --from=uilayer /app/build /go/src/github.com/minio/console/portal-ui/build
32-
RUN go build -ldflags "-w -s" -a -o console ./cmd/console
32+
RUN go build --tags=kqueue,operator -ldflags "-w -s" -a -o console ./cmd/console
3333

3434
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
3535
MAINTAINER MinIO Development "[email protected]"

models/login_request.go

Lines changed: 89 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/principal.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operatorapi/embedded_spec.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operatorapi/operator_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func login(credentials restapi.ConsoleCredentialsI) (*string, error) {
8383
return nil, err
8484
}
8585
// if we made it here, the consoleCredentials work, generate a jwt with claims
86-
token, err := auth.NewEncryptedTokenForClient(&tokens, credentials.GetAccountAccessKey())
86+
token, err := auth.NewEncryptedTokenForClient(&tokens, credentials.GetAccountAccessKey(), nil)
8787
if err != nil {
8888
LogError("error authenticating user: %v", err)
8989
return nil, errInvalidCredentials

operatorapi/proxy.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
123123
return
124124
}
125125

126-
data := map[string]string{
127-
"accessKey": string(tenantConfiguration["accesskey"]),
128-
"secretKey": string(tenantConfiguration["secretkey"]),
126+
data := map[string]interface{}{
127+
"accessKey": tenantConfiguration["accesskey"],
128+
"secretKey": tenantConfiguration["secretkey"],
129+
"features": map[string]bool{
130+
"hide_menu": true,
131+
},
129132
}
130133
payload, _ := json.Marshal(data)
131134

pkg/auth/token.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ type TokenClaims struct {
6666
STSSecretAccessKey string `json:"stsSecretAccessKey,omitempty"`
6767
STSSessionToken string `json:"stsSessionToken,omitempty"`
6868
AccountAccessKey string `json:"accountAccessKey,omitempty"`
69+
HideMenu bool `json:"hm,omitempty"`
70+
}
71+
72+
// SessionFeatures represents features stored in the session
73+
type SessionFeatures struct {
74+
HideMenu bool
6975
}
7076

7177
// SessionTokenAuthenticate takes a session token, decode it, extract claims and validate the signature
@@ -96,14 +102,18 @@ func SessionTokenAuthenticate(token string) (*TokenClaims, error) {
96102

97103
// NewEncryptedTokenForClient generates a new session token with claims based on the provided STS credentials, first
98104
// encrypts the claims and the sign them
99-
func NewEncryptedTokenForClient(credentials *credentials.Value, accountAccessKey string) (string, error) {
105+
func NewEncryptedTokenForClient(credentials *credentials.Value, accountAccessKey string, features *SessionFeatures) (string, error) {
100106
if credentials != nil {
101-
encryptedClaims, err := encryptClaims(&TokenClaims{
107+
tokenClaims := &TokenClaims{
102108
STSAccessKeyID: credentials.AccessKeyID,
103109
STSSecretAccessKey: credentials.SecretAccessKey,
104110
STSSessionToken: credentials.SessionToken,
105111
AccountAccessKey: accountAccessKey,
106-
})
112+
}
113+
if features != nil {
114+
tokenClaims.HideMenu = features.HideMenu
115+
}
116+
encryptedClaims, err := encryptClaims(tokenClaims)
107117
if err != nil {
108118
return "", err
109119
}

pkg/auth/token_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ func TestNewJWTWithClaimsForClient(t *testing.T) {
3636
funcAssert := assert.New(t)
3737
// Test-1 : NewEncryptedTokenForClient() is generated correctly without errors
3838
function := "NewEncryptedTokenForClient()"
39-
token, err := NewEncryptedTokenForClient(creds, "")
39+
token, err := NewEncryptedTokenForClient(creds, "", nil)
4040
if err != nil || token == "" {
4141
t.Errorf("Failed on %s:, error occurred: %s", function, err)
4242
}
4343
// saving token for future tests
4444
goodToken = token
4545
// Test-2 : NewEncryptedTokenForClient() throws error because of empty credentials
46-
if _, err = NewEncryptedTokenForClient(nil, ""); err != nil {
46+
if _, err = NewEncryptedTokenForClient(nil, "", nil); err != nil {
4747
funcAssert.Equal("provided credentials are empty", err.Error())
4848
}
4949
}

portal-ui/src/common/SecureComponent/permissions.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ export const IAM_PAGES = {
129129
TOOLS_LOGS: "/tools/logs",
130130
TOOLS_AUDITLOGS: "/tools/audit-logs",
131131
TOOLS_TRACE: "/tools/trace",
132-
METRICS: "/tools/metrics",
133-
DASHBOARD: "/tools/dashboard",
132+
DASHBOARD: "/tools/metrics",
134133
TOOLS_HEAL: "/tools/heal",
135134
TOOLS_WATCH: "/tools/watch",
136135
/* Health */
@@ -178,6 +177,8 @@ export const IAM_PAGES = {
178177
"/namespaces/:tenantNamespace/tenants/:tenantName/summary",
179178
NAMESPACE_TENANT_METRICS:
180179
"/namespaces/:tenantNamespace/tenants/:tenantName/metrics",
180+
NAMESPACE_TENANT_TRACE:
181+
"/namespaces/:tenantNamespace/tenants/:tenantName/trace",
181182
NAMESPACE_TENANT_POOLS:
182183
"/namespaces/:tenantNamespace/tenants/:tenantName/pools",
183184
NAMESPACE_TENANT_VOLUMES:
@@ -297,9 +298,6 @@ export const IAM_PAGES_PERMISSIONS = {
297298
[IAM_PAGES.DASHBOARD]: [
298299
IAM_SCOPES.ADMIN_SERVER_INFO, // displays dashboard information
299300
],
300-
[IAM_PAGES.METRICS]: [
301-
IAM_SCOPES.ADMIN_SERVER_INFO, // displays dashboard information
302-
],
303301
[IAM_PAGES.POLICIES_VIEW]: [
304302
IAM_SCOPES.ADMIN_DELETE_POLICY,
305303
IAM_SCOPES.ADMIN_LIST_GROUPS,

portal-ui/src/screens/Console/Common/PageHeader/PageHeader.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import React from "react";
17+
import React, { Fragment } from "react";
1818
import { Theme } from "@mui/material/styles";
1919
import { connect } from "react-redux";
2020
import Grid from "@mui/material/Grid";
@@ -38,6 +38,7 @@ interface IPageHeader {
3838
managerObjects?: IFileItem[];
3939
toggleList: typeof toggleList;
4040
middleComponent?: React.ReactNode;
41+
features: string[];
4142
}
4243

4344
const styles = (theme: Theme) =>
@@ -88,7 +89,11 @@ const PageHeader = ({
8889
managerObjects,
8990
toggleList,
9091
middleComponent,
92+
features,
9193
}: IPageHeader) => {
94+
if (features.includes("hide-menu")) {
95+
return <Fragment />;
96+
}
9297
return (
9398
<Grid
9499
container
@@ -157,6 +162,7 @@ const mapState = (state: AppState) => ({
157162
sidebarOpen: state.system.sidebarOpen,
158163
operatorMode: state.system.operatorMode,
159164
managerObjects: state.objectBrowser.objectManager.objectsToManage,
165+
features: state.console.session.features,
160166
});
161167

162168
const mapDispatchToProps = {

0 commit comments

Comments
 (0)