]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: remove the option for authentication with token in 56512/head
authorAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Wed, 27 Mar 2024 09:45:59 +0000 (15:15 +0530)
committerAashish Sharma <aasharma@li-e74156cc-2f67-11b2-a85c-e98659a63c5c.ibm.com>
Mon, 1 Apr 2024 12:05:28 +0000 (17:35 +0530)
multi-cluster form

Signed-off-by: Aashish Sharma <aasharma@redhat.com>
src/pybind/mgr/dashboard/controllers/multi_cluster.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-form/multi-cluster-form.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster-list/multi-cluster-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/multi-cluster.service.ts
src/pybind/mgr/dashboard/openapi.yaml

index ffdf9aed9dc0023549209f789073eacf34e5f71d..de29496e5e7a8eeb0400665de25c988c6947d52b 100644 (file)
@@ -54,9 +54,7 @@ class MultiCluster(RESTController):
     @CreatePermission
     @EndpointDoc("Authenticate to a remote cluster")
     def auth(self, url: str, cluster_alias: str, username: str,
-             password=None, token=None, hub_url=None, cluster_fsid=None,
-             prometheus_api_url=None, ssl_verify=False, ssl_certificate=None, ttl=None):
-
+             password=None, hub_url=None, ssl_verify=False, ssl_certificate=None, ttl=None):
         try:
             hub_fsid = mgr.get('config')['fsid']
         except KeyError:
@@ -101,12 +99,7 @@ class MultiCluster(RESTController):
                                           ssl_verify, ssl_certificate)
             return True
 
-        if token and cluster_fsid and prometheus_api_url:
-            _set_prometheus_targets(prometheus_api_url)
-            self.set_multi_cluster_config(cluster_fsid, username, url,
-                                          cluster_alias, token, prometheus_api_url,
-                                          ssl_verify, ssl_certificate)
-        return True
+        return False
 
     def check_cluster_connection(self, url, payload, username, ssl_verify, ssl_certificate):
         try:
@@ -200,7 +193,7 @@ class MultiCluster(RESTController):
     @Endpoint('PUT')
     @UpdatePermission
     # pylint: disable=W0613
-    def reconnect_cluster(self, url: str, username=None, password=None, token=None,
+    def reconnect_cluster(self, url: str, username=None, password=None,
                           ssl_verify=False, ssl_certificate=None, ttl=None):
         multicluster_config = self.load_multi_cluster_config()
         if username and password:
index 30c32c0ec608772a409c7519fd14e7a1e2f75eb7..6cc09c772b18f5edcf28c176326eb3a28da0ad80 100644 (file)
                         spacingClass="mb-3"
                         i18n>{{ connectionMessage }}
         </cd-alert-panel>
-        <cd-alert-panel type="info"
-                        spacingClass="mb-3"
-                        i18n
-                        *ngIf="connectionVerified !== undefined && !connectionVerified && connectionMessage === 'Connection refused' || remoteClusterForm.getValue('showToken')">
-        <p>You need to set this cluster's url as the cross origin url in the remote cluster you are trying to connect.
-          You can do it by running this CLI command in your remote cluster and proceed with authentication via token.</p>
-          <cd-code-block [codes]="[crossOriginCmd]"></cd-code-block>
-        </cd-alert-panel>
         <div class="form-group row">
           <label class="cd-col-form-label required"
                  for="remoteClusterUrl"
                   *ngIf="remoteClusterForm.showError('remoteClusterUrl', frm, 'endpoint')"
                   i18n>Please enter a valid URL.
             </span>
+            <span class="invalid-feedback"
+                  *ngIf="remoteClusterForm.showError('remoteClusterUrl', frm, 'hubUrlCheck')"
+                  i18n>The hub cluster cannot be connected.
+            </span>
           </div>
         </div>
         <div class="form-group row">
           </div>
         </div>
         <div class="form-group row"
-             *ngIf="remoteClusterForm.getValue('showToken') && action !== 'edit'">
-          <label class="cd-col-form-label required"
-                 for="clusterFsid"
-                 i18n>Cluster FSID
-          </label>
-          <div class="cd-col-form-input">
-            <input id="clusterFsid"
-                   name="clusterFsid"
-                   class="form-control"
-                   type="text"
-                   formControlName="clusterFsid">
-            <span class="invalid-feedback"
-                  *ngIf="remoteClusterForm.showError('clusterFsid', frm, 'required')"
-                  i18n>This field is required.
-            </span>
-          </div>
-        </div>
-        <div class="form-group row"
-             *ngIf="remoteClusterForm.getValue('showToken') && action !== 'edit'">
-          <label class="cd-col-form-label required"
-                 for="prometheusApiUrl"
-                 i18n>Prometheus API URL
-            <cd-helper>
-              <span>
-                <p>Enter the Prometheus API URL. You can retrieve it from the CLI with: <b>{{ prometheusApiUrlCmd }} </b>
-                  <cd-copy-2-clipboard-button [source]="prometheusApiUrlCmd"
-                                              [byId]="false"></cd-copy-2-clipboard-button>
-                </p>
-              </span>
-            </cd-helper>
-          </label>
-          <div class="cd-col-form-input">
-            <input id="prometheusApiUrl"
-                   name="prometheusApiUrl"
-                   class="form-control"
-                   type="text"
-                   formControlName="prometheusApiUrl">
-            <span class="invalid-feedback"
-                  *ngIf="remoteClusterForm.showError('prometheusApiUrl', frm, 'required')"
-                  i18n>This field is required.
-            </span>
-          </div>
-        </div>
-        <div class="form-group row"
-             *ngIf="!remoteClusterForm.getValue('showToken') && !showCrossOriginError && action !== 'edit'">
+             *ngIf="action !== 'edit'">
           <label class="cd-col-form-label required"
                  for="password"
                  i18n>Password
           </div>
         </div>
         <div class="form-group row"
-             *ngIf="remoteClusterForm.getValue('showToken') && action !== 'edit'">
-          <label class="cd-col-form-label required"
-                 for="apiToken"
-                 i18n>Token
-          </label>
-          <div class="cd-col-form-input">
-            <input id="apiToken"
-                   name="apiToken"
-                   class="form-control"
-                   type="text"
-                   formControlName="apiToken">
-            <span class="invalid-feedback"
-                  *ngIf="remoteClusterForm.showError('apiToken', frm, 'required')"
-                  i18n>This field is required.</span>
-          </div>
-        </div>
-        <div class="form-group row"
-             *ngIf="!remoteClusterForm.getValue('showToken') && action !== 'edit'">
+             *ngIf="action !== 'edit'">
           <label class="cd-col-form-label"
                  for="ttl"
                  i18n>Login Expiration</label>
             </select>
           </div>
         </div>
+        <!--
+        <div class="form-group row"
+             *ngIf="action !== 'edit'">
+          <label class="cd-col-form-label required"
+                 for="apiToken"
+                 i18n>Token
+          </label>
+          <div class="cd-col-form-input">
+            <input id="apiToken"
+                   name="apiToken"
+                   class="form-control"
+                   type="text"
+                   formControlName="apiToken">
+            <span class="invalid-feedback"
+                  *ngIf="remoteClusterForm.showError('apiToken', frm, 'required')"
+                  i18n>This field is required.</span>
+          </div>
+        </div>
         <div class="form-group row"
              *ngIf="action !== 'edit'">
           <div class="cd-col-form-offset">
                      i18n>Auth with token</label>
             </div>
           </div>
-        </div>
+        </div> -->
         <!-- ssl -->
         <div class="form-group row">
           <div class="cd-col-form-offset">
index 4a6ed695cba44301924c5c64c2343cbdc1416d5f..18da2ad48d3fbebfef7ffac364764e8e0551539e 100644 (file)
@@ -23,14 +23,10 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
   readonly ipv4Rgx = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i;
   readonly ipv6Rgx = /^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i;
   clusterApiUrlCmd = 'ceph mgr services';
-  prometheusApiUrlCmd = 'ceph config get mgr mgr/dashboard/PROMETHEUS_API_HOST';
-  crossOriginCmd = `ceph dashboard set-cross-origin-url ${window.location.origin}`;
   remoteClusterForm: CdFormGroup;
-  showToken = false;
   connectionVerified: boolean;
   connectionMessage = '';
   private subs = new Subscription();
-  showCrossOriginError = false;
   action: string;
   cluster: MultiCluster;
   clustersData: MultiCluster[];
@@ -38,6 +34,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
   clusterUrls: string[];
   clusterUsers: string[];
   clusterUrlUserMap: Map<string, string>;
+  hubUrl: string;
 
   constructor(
     public activeModal: NgbActiveModal,
@@ -45,6 +42,11 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
     public notificationService: NotificationService,
     private multiClusterService: MultiClusterService
   ) {
+    this.subs.add(
+      this.multiClusterService.subscribe((resp: any) => {
+        this.hubUrl = resp['hub_url'];
+      })
+    );
     this.createForm();
   }
   ngOnInit(): void {
@@ -62,8 +64,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
       this.remoteClusterForm.get('clusterAlias').disable();
       this.remoteClusterForm.get('username').setValue(this.cluster.user);
       this.remoteClusterForm.get('username').disable();
-      this.remoteClusterForm.get('clusterFsid').setValue(this.cluster.name);
-      this.remoteClusterForm.get('clusterFsid').disable();
       this.remoteClusterForm.get('ssl').setValue(this.cluster.ssl_verify);
       this.remoteClusterForm.get('ssl_cert').setValue(this.cluster.ssl_certificate);
     }
@@ -76,7 +76,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
 
   createForm() {
     this.remoteClusterForm = new CdFormGroup({
-      showToken: new FormControl(false),
+      // showToken: new FormControl(false),
       username: new FormControl('', [
         CdValidators.custom('uniqueUrlandUser', (username: string) => {
           let remoteClusterUrl = '';
@@ -96,16 +96,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
           );
         })
       ]),
-      clusterFsid: new FormControl('', [
-        CdValidators.requiredIf({
-          showToken: true
-        })
-      ]),
-      prometheusApiUrl: new FormControl('', [
-        CdValidators.requiredIf({
-          showToken: true
-        })
-      ]),
       password: new FormControl('', []),
       remoteClusterUrl: new FormControl(null, {
         validators: [
@@ -120,14 +110,17 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
               );
             }
           }),
+          CdValidators.custom('hubUrlCheck', (remoteClusterUrl: string) => {
+            return this.action === 'connect' && remoteClusterUrl?.includes(this.hubUrl);
+          }),
           Validators.required
         ]
       }),
-      apiToken: new FormControl('', [
-        CdValidators.requiredIf({
-          showToken: true
-        })
-      ]),
+      // apiToken: new FormControl('', [
+      //   CdValidators.requiredIf({
+      //     showToken: true
+      //   })
+      // ]),
       clusterAlias: new FormControl(null, {
         validators: [
           Validators.required,
@@ -159,9 +152,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
   handleError(error: any): void {
     if (error.error.code === 'connection_refused') {
       this.connectionVerified = false;
-      this.showCrossOriginError = true;
       this.connectionMessage = error.error.detail;
-      this.crossOriginCmd = `ceph config set mgr mgr/dashboard/cross_origin_url ${window.location.origin} `;
     } else {
       this.connectionVerified = false;
       this.connectionMessage = error.error.detail;
@@ -189,9 +180,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
     const clusterAlias = this.remoteClusterForm.getValue('clusterAlias');
     const username = this.remoteClusterForm.getValue('username');
     const password = this.remoteClusterForm.getValue('password');
-    const token = this.remoteClusterForm.getValue('apiToken');
-    const clusterFsid = this.remoteClusterForm.getValue('clusterFsid');
-    const prometheusApiUrl = this.remoteClusterForm.getValue('prometheusApiUrl');
     const ssl = this.remoteClusterForm.getValue('ssl');
     const ttl = this.convertToHours(this.remoteClusterForm.getValue('ttl'));
     const ssl_certificate = this.remoteClusterForm.getValue('ssl_cert')?.trim();
@@ -219,7 +207,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
       case 'reconnect':
         this.subs.add(
           this.multiClusterService
-            .reConnectCluster(updatedUrl, username, password, token, ssl, ssl_certificate, ttl)
+            .reConnectCluster(updatedUrl, username, password, ssl, ssl_certificate, ttl)
             .subscribe(commonSubscribtion)
         );
         break;
@@ -231,10 +219,7 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
               clusterAlias,
               username,
               password,
-              token,
               window.location.origin,
-              clusterFsid,
-              prometheusApiUrl,
               ssl,
               ssl_certificate,
               ttl
@@ -247,10 +232,6 @@ export class MultiClusterFormComponent implements OnInit, OnDestroy {
     }
   }
 
-  toggleToken() {
-    this.showToken = !this.showToken;
-  }
-
   fileUpload(files: FileList, controlName: string) {
     const file: File = files[0];
     const reader = new FileReader();
index 5d0b20f5edd93ce159219280a87d6485864558d5..5fc1d5d6d06d7afd5a940ef67860219773d756af 100644 (file)
@@ -19,6 +19,7 @@ import { MultiCluster } from '~/app/shared/models/multi-cluster';
 import { Router } from '@angular/router';
 import { CookiesService } from '~/app/shared/services/cookie.service';
 import { Observable, Subscription } from 'rxjs';
+import { SettingsService } from '~/app/shared/api/settings.service';
 
 @Component({
   selector: 'cd-multi-cluster-list',
@@ -55,7 +56,8 @@ export class MultiClusterListComponent implements OnInit, OnDestroy {
     private notificationService: NotificationService,
     private authStorageService: AuthStorageService,
     private modalService: ModalService,
-    private cookieService: CookiesService
+    private cookieService: CookiesService,
+    private settingsService: SettingsService
   ) {
     this.tableActions = [
       {
@@ -162,6 +164,8 @@ export class MultiClusterListComponent implements OnInit, OnDestroy {
         this.checkClusterConnectionStatus();
       })
     );
+
+    this.managedByConfig$ = this.settingsService.getValues('MANAGED_BY_CLUSTERS');
   }
 
   ngOnDestroy(): void {
index a26e1b7f199ab97846c2d828e330faff850f934f..3c4be090f076df9408e1ba243d9f5b214b03fa16 100644 (file)
@@ -128,10 +128,7 @@ export class MultiClusterService {
     clusterAlias: string,
     username: string,
     password: string,
-    token = '',
     hub_url = '',
-    clusterFsid = '',
-    prometheusApiUrl = '',
     ssl = false,
     cert = '',
     ttl: number
@@ -141,10 +138,7 @@ export class MultiClusterService {
       cluster_alias: clusterAlias,
       username,
       password,
-      token,
       hub_url,
-      cluster_fsid: clusterFsid,
-      prometheus_api_url: prometheusApiUrl,
       ssl_verify: ssl,
       ssl_certificate: cert,
       ttl: ttl
@@ -155,7 +149,6 @@ export class MultiClusterService {
     url: any,
     username: string,
     password: string,
-    token = '',
     ssl = false,
     cert = '',
     ttl: number
@@ -164,7 +157,6 @@ export class MultiClusterService {
       url,
       username,
       password,
-      token,
       ssl_verify: ssl,
       ssl_certificate: cert,
       ttl: ttl
index ae0f9e03921728cb05a6d35f3fb3fd676c5145b8..56b67342399fdb64b4ae30a514391972bcf7213f 100644 (file)
@@ -7103,21 +7103,15 @@ paths:
               properties:
                 cluster_alias:
                   type: string
-                cluster_fsid:
-                  type: string
                 hub_url:
                   type: string
                 password:
                   type: string
-                prometheus_api_url:
-                  type: string
                 ssl_certificate:
                   type: string
                 ssl_verify:
                   default: false
                   type: boolean
-                token:
-                  type: string
                 ttl:
                   type: string
                 url:
@@ -7298,8 +7292,6 @@ paths:
                 ssl_verify:
                   default: false
                   type: boolean
-                token:
-                  type: string
                 ttl:
                   type: string
                 url: