forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
1090 lines (994 loc) · 42.2 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package config
import (
"errors"
"fmt"
"os"
"sort"
"strings"
"sync"
"gopkg.in/yaml.v2"
"github.com/kiali/kiali/config/dashboards"
"github.com/kiali/kiali/config/security"
"github.com/kiali/kiali/log"
)
// Files found in /kiali-override-secrets that override the ConfigMap yaml values
const (
// External services auth
SecretFileGrafanaPassword = "grafana-password"
SecretFileGrafanaToken = "grafana-token"
SecretFilePrometheusPassword = "prometheus-password"
SecretFilePrometheusToken = "prometheus-token"
SecretFileTracingPassword = "tracing-password"
SecretFileTracingToken = "tracing-token"
// Login Token signing key used to prepare the token for user login
SecretFileLoginTokenSigningKey = "login-token-signing-key"
)
// The valid auth strategies and values for cookie handling
const (
AuthStrategyOpenshift = "openshift"
AuthStrategyAnonymous = "anonymous"
AuthStrategyToken = "token"
AuthStrategyOpenId = "openid"
AuthStrategyHeader = "header"
TokenCookieName = "kiali-token"
// These constants are used for external services auth (Prometheus, Grafana ...) ; not for Kiali auth
AuthTypeBasic = "basic"
AuthTypeBearer = "bearer"
AuthTypeNone = "none"
)
const (
IstioMultiClusterHostSuffix = "global"
OidcClientSecretFile = "/kiali-secret/oidc-secret"
)
const (
DashboardsDiscoveryEnabled = "true"
DashboardsDiscoveryAuto = "auto"
)
const (
// DefaultClusterID is generally not for use outside of test-code. In general you should use config.Get().KubernetesConfig.ClusterName
DefaultClusterID = "Kubernetes"
)
const (
AmbientAnnotation = "ambient.istio.io/redirection"
AmbientAnnotationEnabled = "enabled"
WaypointLabel = "gateway.istio.io/managed"
WaypointLabelValue = "istio.io-mesh-controller"
)
// FeatureName is the enum type used for named features that can be disabled via KialiFeatureFlags.DisabledFeatures
type FeatureName string
const (
FeatureLogView FeatureName = "logs-tab"
)
func (fn FeatureName) IsValid() error {
switch fn {
case FeatureLogView:
return nil
}
return fmt.Errorf("Invalid feature name: %v", fn)
}
// Global configuration for the application.
var (
configuration Config
rwMutex sync.RWMutex
)
// Defines where the files are located that contain the secrets content
var overrideSecretsDir = "/kiali-override-secrets"
// Metrics provides metrics configuration for the Kiali server.
type Metrics struct {
Enabled bool `yaml:"enabled,omitempty"`
Port int `yaml:"port,omitempty"`
}
// OpenTelemetry collector configuration for tracing
type OtelCollector struct {
CAName string `yaml:"ca_name,omitempty"`
Protocol string `yaml:"protocol,omitempty"` // http or https or grpc
SkipVerify bool `yaml:"skip_verify,omitempty"`
TLSEnabled bool `yaml:"tls_enabled,omitempty"`
}
// Tracing provides tracing configuration for the Kiali server.
type Tracing struct {
CollectorType string `yaml:"collector_type,omitempty"` // Possible values "otel" or "jaeger"
CollectorURL string `yaml:"collector_url,omitempty"` // Endpoint for Kiali server traces
Enabled bool `yaml:"enabled,omitempty"`
Otel OtelCollector `yaml:"otel,omitempty"`
// Sampling rate for Kiali server traces. >= 1.0 always samples and <= 0 never samples.
SamplingRate float64 `yaml:"sampling_rate,omitempty"`
}
// Observability provides configuration for tracing and metrics exported by the Kiali server.
type Observability struct {
Metrics Metrics `yaml:"metrics,omitempty"`
Tracing Tracing `yaml:"tracing,omitempty"`
}
// Server configuration
type Server struct {
Address string `yaml:",omitempty"`
AuditLog bool `yaml:"audit_log,omitempty"` // When true, allows additional audit logging on Write operations
CORSAllowAll bool `yaml:"cors_allow_all,omitempty"`
GzipEnabled bool `yaml:"gzip_enabled,omitempty"`
Observability Observability `yaml:"observability,omitempty"`
Port int `yaml:",omitempty"`
StaticContentRootDirectory string `yaml:"static_content_root_directory,omitempty"`
WebFQDN string `yaml:"web_fqdn,omitempty"`
WebPort string `yaml:"web_port,omitempty"`
WebRoot string `yaml:"web_root,omitempty"`
WebHistoryMode string `yaml:"web_history_mode,omitempty"`
WebSchema string `yaml:"web_schema,omitempty"`
}
// Auth provides authentication data for external services
type Auth struct {
CAFile string `yaml:"ca_file"`
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
Password string `yaml:"password"`
Token string `yaml:"token"`
Type string `yaml:"type"`
UseKialiToken bool `yaml:"use_kiali_token"`
Username string `yaml:"username"`
}
func (a *Auth) Obfuscate() {
a.Token = "xxx"
a.Password = "xxx"
a.Username = "xxx"
a.CAFile = "xxx"
}
// ThanosProxy describes configuration of the Thanos proxy component
type ThanosProxy struct {
Enabled bool `yaml:"enabled,omitempty"`
RetentionPeriod string `yaml:"retention_period,omitempty"`
ScrapeInterval string `yaml:"scrape_interval,omitempty"`
}
// PrometheusConfig describes configuration of the Prometheus component
type PrometheusConfig struct {
Auth Auth `yaml:"auth,omitempty"`
CacheDuration int `yaml:"cache_duration,omitempty"` // Cache duration per query expressed in seconds
CacheEnabled bool `yaml:"cache_enabled,omitempty"` // Enable cache for Prometheus queries
CacheExpiration int `yaml:"cache_expiration,omitempty"` // Global cache expiration expressed in seconds
CustomHeaders map[string]string `yaml:"custom_headers,omitempty"`
HealthCheckUrl string `yaml:"health_check_url,omitempty"`
IsCore bool `yaml:"is_core,omitempty"`
QueryScope map[string]string `yaml:"query_scope,omitempty"`
ThanosProxy ThanosProxy `yaml:"thanos_proxy,omitempty"`
URL string `yaml:"url,omitempty"`
}
// CustomDashboardsConfig describes configuration specific to Custom Dashboards
type CustomDashboardsConfig struct {
DiscoveryEnabled string `yaml:"discovery_enabled,omitempty"`
DiscoveryAutoThreshold int `yaml:"discovery_auto_threshold,omitempty"`
Enabled bool `yaml:"enabled,omitempty"`
IsCore bool `yaml:"is_core,omitempty"`
NamespaceLabel string `yaml:"namespace_label,omitempty"`
Prometheus PrometheusConfig `yaml:"prometheus,omitempty"`
}
// GrafanaConfig describes configuration used for Grafana links
type GrafanaConfig struct {
Auth Auth `yaml:"auth"`
Dashboards []GrafanaDashboardConfig `yaml:"dashboards"`
Enabled bool `yaml:"enabled"` // Enable or disable Grafana support in Kiali
HealthCheckUrl string `yaml:"health_check_url,omitempty"`
InClusterURL string `yaml:"in_cluster_url"`
IsCore bool `yaml:"is_core,omitempty"`
URL string `yaml:"url"`
}
type GrafanaDashboardConfig struct {
Name string `yaml:"name"`
Variables GrafanaVariablesConfig `yaml:"variables"`
}
type GrafanaVariablesConfig struct {
App string `yaml:"app" json:"app,omitempty"`
Namespace string `yaml:"namespace" json:"namespace,omitempty"`
Service string `yaml:"service" json:"service,omitempty"`
Version string `yaml:"version" json:"version,omitempty"`
Workload string `yaml:"workload" json:"workload,omitempty"`
}
// TracingConfig describes configuration used for tracing links
type TracingConfig struct {
Auth Auth `yaml:"auth"`
Enabled bool `yaml:"enabled"` // Enable Tracing in Kiali
GrpcPort int `yaml:"grpc_port,omitempty"`
InClusterURL string `yaml:"in_cluster_url"`
IsCore bool `yaml:"is_core,omitempty"`
Provider string `yaml:"provider"` // jaeger | tempo
NamespaceSelector bool `yaml:"namespace_selector"`
QueryScope map[string]string `yaml:"query_scope,omitempty"`
QueryTimeout int `yaml:"query_timeout,omitempty"`
URL string `yaml:"url"`
UseGRPC bool `yaml:"use_grpc"`
WhiteListIstioSystem []string `yaml:"whitelist_istio_system"`
}
// RegistryConfig contains configuration for connecting to an external istiod.
// This is used when Kiali should connect to the istiod via a url instead of port forwarding.
type RegistryConfig struct {
IstiodURL string `yaml:"istiod_url"`
// TODO: Support auth options
}
// IstioConfig describes configuration used for istio links
type IstioConfig struct {
ComponentStatuses ComponentStatuses `yaml:"component_status,omitempty"`
ConfigMapName string `yaml:"config_map_name,omitempty"`
EnvoyAdminLocalPort int `yaml:"envoy_admin_local_port,omitempty"`
GatewayAPIClasses []GatewayAPIClass `yaml:"gateway_api_classes,omitempty"`
IstioAPIEnabled bool `yaml:"istio_api_enabled"`
IstioCanaryRevision IstioCanaryRevision `yaml:"istio_canary_revision,omitempty"`
IstioIdentityDomain string `yaml:"istio_identity_domain,omitempty"`
IstioInjectionAnnotation string `yaml:"istio_injection_annotation,omitempty"`
IstioSidecarInjectorConfigMapName string `yaml:"istio_sidecar_injector_config_map_name,omitempty"`
IstioSidecarAnnotation string `yaml:"istio_sidecar_annotation,omitempty"`
IstiodDeploymentName string `yaml:"istiod_deployment_name,omitempty"`
IstiodPodMonitoringPort int `yaml:"istiod_pod_monitoring_port,omitempty"`
// IstiodPollingIntervalSeconds is how often in seconds Kiali will poll istiod(s) for
// proxy status and registry services. Polling is not performed if IstioAPIEnabled is false.
IstiodPollingIntervalSeconds int `yaml:"istiod_polling_interval_seconds,omitempty"`
Registry *RegistryConfig `yaml:"registry,omitempty"`
RootNamespace string `yaml:"root_namespace,omitempty"`
UrlServiceVersion string `yaml:"url_service_version"`
}
type IstioCanaryRevision struct {
Current string `yaml:"current,omitempty"`
Upgrade string `yaml:"upgrade,omitempty"`
}
type ComponentStatuses struct {
Enabled bool `yaml:"enabled,omitempty"`
Components []ComponentStatus `yaml:"components,omitempty"`
}
type ComponentStatus struct {
AppLabel string `yaml:"app_label,omitempty"`
IsCore bool `yaml:"is_core,omitempty"`
IsProxy bool `yaml:"is_proxy,omitempty"`
IsMultiCluster bool `yaml:"is_multicluster,omitempty"`
Namespace string `yaml:"namespace,omitempty"`
}
type GatewayAPIClass struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
ClassName string `yaml:"class_name,omitempty" json:"className,omitempty"`
}
// ExternalServices holds configurations for other systems that Kiali depends on
type ExternalServices struct {
Grafana GrafanaConfig `yaml:"grafana,omitempty"`
Istio IstioConfig `yaml:"istio,omitempty"`
Prometheus PrometheusConfig `yaml:"prometheus,omitempty"`
CustomDashboards CustomDashboardsConfig `yaml:"custom_dashboards,omitempty"`
Tracing TracingConfig `yaml:"tracing,omitempty"`
}
// LoginToken holds config used for generating the Kiali session tokens.
type LoginToken struct {
ExpirationSeconds int64 `yaml:"expiration_seconds,omitempty"`
SigningKey string `yaml:"signing_key,omitempty"`
}
func (lt *LoginToken) Obfuscate() {
lt.SigningKey = "xxx"
}
// IstioLabels holds configuration about the labels required by Istio
type IstioLabels struct {
AmbientNamespaceLabel string
AmbientNamespaceLabelValue string
AmbientWaypointLabel string
AmbientWaypointLabelValue string
AppLabelName string `yaml:"app_label_name,omitempty" json:"appLabelName"`
InjectionLabelName string `yaml:"injection_label,omitempty" json:"injectionLabelName"`
InjectionLabelRev string `yaml:"injection_label_rev,omitempty" json:"injectionLabelRev"`
VersionLabelName string `yaml:"version_label_name,omitempty" json:"versionLabelName"`
}
// AdditionalDisplayItem holds some display-related configuration, like which annotations are to be displayed
type AdditionalDisplayItem struct {
Annotation string `yaml:"annotation"`
IconAnnotation string `yaml:"icon_annotation"`
Title string `yaml:"title"`
}
// KubernetesConfig holds the k8s client, caching and performance configuration
type KubernetesConfig struct {
Burst int `yaml:"burst,omitempty"`
// Cache duration expressed in seconds
// Cache uses watchers to sync with the backend, after a CacheDuration watchers are closed and re-opened
CacheDuration int `yaml:"cache_duration,omitempty"`
// Cache duration expressed in seconds
// Kiali cache list of namespaces per user, this is typically short lived cache compared with the duration of the
// namespace cache defined by previous CacheDuration parameter
CacheTokenNamespaceDuration int `yaml:"cache_token_namespace_duration,omitempty"`
// ClusterName is the name of the kubernetes cluster that Kiali is running in.
// If empty, then it will default to 'Kubernetes'.
ClusterName string `yaml:"cluster_name,omitempty"`
// List of controllers that won't be used for Workload calculation
// Kiali queries Deployment,ReplicaSet,ReplicationController,DeploymentConfig,StatefulSet,Job and CronJob controllers
// Deployment and ReplicaSet will be always queried, but ReplicationController,DeploymentConfig,StatefulSet,Job and CronJobs
// can be skipped from Kiali workloads query if they are present in this list
ExcludeWorkloads []string `yaml:"excluded_workloads,omitempty"`
QPS float32 `yaml:"qps,omitempty"`
}
// ApiConfig contains API specific configuration.
type ApiConfig struct {
Namespaces ApiNamespacesConfig
}
// ApiNamespacesConfig provides a list of regex strings defining namespaces to include or exclude.
type ApiNamespacesConfig struct {
Exclude []string `yaml:"exclude,omitempty" json:"exclude"`
Include []string `yaml:"include,omitempty" json:"include"`
LabelSelectorExclude string `yaml:"label_selector_exclude,omitempty" json:"labelSelectorExclude"`
LabelSelectorInclude string `yaml:"label_selector_include,omitempty" json:"labelSelectorInclude"`
}
// AuthConfig provides details on how users are to authenticate
type AuthConfig struct {
OpenId OpenIdConfig `yaml:"openid,omitempty"`
OpenShift OpenShiftConfig `yaml:"openshift,omitempty"`
Strategy string `yaml:"strategy,omitempty"`
}
// OpenShiftConfig contains specific configuration for authentication when on OpenShift
type OpenShiftConfig struct {
AuthTimeout int `yaml:"auth_timeout,omitempty"`
ClientIdPrefix string `yaml:"client_id_prefix,omitempty"`
ClientId string `yaml:"client_id,omitempty"`
ServerPrefix string `yaml:"server_prefix,omitempty"`
UseSystemCA bool `yaml:"use_system_ca,omitempty"`
CustomCA string `yaml:"custom_ca,omitempty"`
}
// OpenIdConfig contains specific configuration for authentication using an OpenID provider
type OpenIdConfig struct {
AdditionalRequestParams map[string]string `yaml:"additional_request_params,omitempty"`
AllowedDomains []string `yaml:"allowed_domains,omitempty"`
ApiProxy string `yaml:"api_proxy,omitempty"`
ApiProxyCAData string `yaml:"api_proxy_ca_data,omitempty"`
ApiToken string `yaml:"api_token,omitempty"`
AuthenticationTimeout int `yaml:"authentication_timeout,omitempty"`
AuthorizationEndpoint string `yaml:"authorization_endpoint,omitempty"`
ClientId string `yaml:"client_id,omitempty"`
ClientSecret string `yaml:"client_secret,omitempty"`
DisableRBAC bool `yaml:"disable_rbac,omitempty"`
HTTPProxy string `yaml:"http_proxy,omitempty"`
HTTPSProxy string `yaml:"https_proxy,omitempty"`
InsecureSkipVerifyTLS bool `yaml:"insecure_skip_verify_tls,omitempty"`
IssuerUri string `yaml:"issuer_uri,omitempty"`
Scopes []string `yaml:"scopes,omitempty"`
UsernameClaim string `yaml:"username_claim,omitempty"`
}
// DeploymentConfig provides details on how Kiali was deployed.
type DeploymentConfig struct {
AccessibleNamespaces []string `yaml:"accessible_namespaces"`
ClusterWideAccess bool `yaml:"cluster_wide_access,omitempty"`
InstanceName string `yaml:"instance_name"`
Namespace string `yaml:"namespace,omitempty"` // Kiali deployment namespace
ViewOnlyMode bool `yaml:"view_only_mode,omitempty"`
// RemoteSecretPath is used to identify the remote cluster Kiali will connect to as its "local cluster".
// This is to support installing Kiali in the control plane, but observing only the data plane in the remote cluster.
// Experimental feature. See: https://github.com/kiali/kiali/issues/3002
RemoteSecretPath string `yaml:"remote_secret_path,omitempty"`
}
// GraphFindOption defines a single Graph Find/Hide Option
type GraphFindOption struct {
AutoSelect bool `yaml:"auto_select,omitempty" json:"autoSelect,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Expression string `yaml:"expression,omitempty" json:"expression,omitempty"`
}
// GraphSettings affect the graph visualization.
// FontLabel: font used for node text (edge label font is determined from this value)
// MinFontBadge: smallest effective font (zoomed font) before removing node badges
// MinFontLabel: smallest effective node text font (zoomed font) before removing labels
type GraphSettings struct {
FontLabel float32 `yaml:"font_label,omitempty" json:"fontLabel,omitempty"`
MinFontBadge float32 `yaml:"min_font_badge,omitempty" json:"minFontBadge,omitempty"`
MinFontLabel float32 `yaml:"min_font_label,omitempty" json:"minFontLabel,omitempty"`
}
// GraphTraffic defines the protocol-specific rates used to determine traffic for graph generation.
// grpc options : none | sent (messages) | received (messages) | requests (default) | total (messages)
// http options : none | requests (default)
// tcp options : none | sent (bytes, default) | received (bytes) | total (bytes)
type GraphTraffic struct {
Grpc string `yaml:"grpc,omitempty" json:"grpc,omitempty"`
Http string `yaml:"http,omitempty" json:"http,omitempty"`
Tcp string `yaml:"tcp,omitempty" json:"tcp,omitempty"`
}
// GraphUIDefaults defines UI Defaults specific to the UI Graph
type GraphUIDefaults struct {
FindOptions []GraphFindOption `yaml:"find_options,omitempty" json:"findOptions,omitempty"`
HideOptions []GraphFindOption `yaml:"hide_options,omitempty" json:"hideOptions,omitempty"`
Impl string `yaml:"impl,omitempty" json:"impl,omitempty"`
Settings GraphSettings `yaml:"settings,omitempty" json:"settings,omitempty"`
Traffic GraphTraffic `yaml:"traffic,omitempty" json:"traffic,omitempty"`
}
// ListUIDefaults defines UI Defaults specific to the UI List pages
type ListUIDefaults struct {
IncludeHealth bool `yaml:"include_health,omitempty" json:"includeHealth"`
IncludeIstioResources bool `yaml:"include_istio_resources,omitempty" json:"includeIstioResources"`
IncludeValidations bool `yaml:"include_validations,omitempty" json:"includeValidations"`
ShowIncludeToggles bool `yaml:"show_include_toggles,omitempty" json:"showIncludeToggles"`
}
// Aggregation represents label's allowed aggregations, transformed from aggregation in MonitoringDashboard config resource
type Aggregation struct {
Label string `yaml:"label,omitempty" json:"label"`
DisplayName string `yaml:"display_name,omitempty" json:"displayName"`
SingleSelection bool `yaml:"single_selection,omitempty" json:"singleSelection"`
}
type MetricsDefaults struct {
Aggregations []Aggregation `yaml:"aggregations,omitempty" json:"aggregations,omitempty"`
}
// UIDefaults defines default settings configured for the UI
type UIDefaults struct {
Graph GraphUIDefaults `yaml:"graph,omitempty" json:"graph,omitempty"`
List ListUIDefaults `yaml:"list,omitempty" json:"list,omitempty"`
MetricsPerRefresh string `yaml:"metrics_per_refresh,omitempty" json:"metricsPerRefresh,omitempty"`
MetricsInbound MetricsDefaults `yaml:"metrics_inbound,omitempty" json:"metricsInbound,omitempty"`
MetricsOutbound MetricsDefaults `yaml:"metrics_outbound,omitempty" json:"metricsOutbound,omitempty"`
Namespaces []string `yaml:"namespaces,omitempty" json:"namespaces,omitempty"`
RefreshInterval string `yaml:"refresh_interval,omitempty" json:"refreshInterval,omitempty"`
}
// Validations defines default settings configured for the Validations subsystem
type Validations struct {
Ignore []string `yaml:"ignore,omitempty" json:"ignore,omitempty"`
SkipWildcardGatewayHosts bool `yaml:"skip_wildcard_gateway_hosts,omitempty"`
}
// CertificatesInformationIndicators defines configuration to enable the feature and to grant read permissions to a list of secrets
type CertificatesInformationIndicators struct {
Enabled bool `yaml:"enabled,omitempty" json:"enabled"`
Secrets []string `yaml:"secrets,omitempty" json:"secrets,omitempty"`
}
// Clustering defines configuration around multi-cluster functionality.
type Clustering struct {
EnableExecProvider bool `yaml:"enable_exec_provider,omitempty" json:"enable_exec_provider"`
KialiURLs []KialiURL `yaml:"kiali_urls,omitempty" json:"kiali_urls,omitempty"`
}
// KialiURL defines a cluster name, namespace and instance name properties to URL.
type KialiURL struct {
ClusterName string `yaml:"cluster_name,omitempty"`
InstanceName string `yaml:"instance_name,omitempty"`
Namespace string `yaml:"namespace,omitempty"`
URL string `yaml:"url,omitempty"`
}
// KialiFeatureFlags available from the CR
type KialiFeatureFlags struct {
CertificatesInformationIndicators CertificatesInformationIndicators `yaml:"certificates_information_indicators,omitempty" json:"certificatesInformationIndicators"`
Clustering Clustering `yaml:"clustering,omitempty" json:"clustering,omitempty"`
DisabledFeatures []string `yaml:"disabled_features,omitempty" json:"disabledFeatures,omitempty"`
IstioAnnotationAction bool `yaml:"istio_annotation_action,omitempty" json:"istioAnnotationAction"`
IstioInjectionAction bool `yaml:"istio_injection_action,omitempty" json:"istioInjectionAction"`
IstioUpgradeAction bool `yaml:"istio_upgrade_action,omitempty" json:"istioUpgradeAction"`
UIDefaults UIDefaults `yaml:"ui_defaults,omitempty" json:"uiDefaults,omitempty"`
Validations Validations `yaml:"validations,omitempty" json:"validations,omitempty"`
}
// Tolerance config
type Tolerance struct {
Code string `yaml:"code,omitempty" json:"code"`
Degraded float32 `yaml:"degraded,omitempty" json:"degraded"`
Failure float32 `yaml:"failure,omitempty" json:"failure"`
Protocol string `yaml:"protocol,omitempty" json:"protocol"`
Direction string `yaml:"direction,omitempty" json:"direction"`
}
// Rate config
type Rate struct {
Namespace string `yaml:"namespace,omitempty" json:"namespace,omitempty"`
Kind string `yaml:"kind,omitempty" json:"kind,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Tolerance []Tolerance `yaml:"tolerance,omitempty" json:"tolerance"`
}
// HealthConfig rates
type HealthConfig struct {
Rate []Rate `yaml:"rate,omitempty" json:"rate,omitempty"`
}
// Config defines full YAML configuration.
type Config struct {
AdditionalDisplayDetails []AdditionalDisplayItem `yaml:"additional_display_details,omitempty"`
API ApiConfig `yaml:"api,omitempty"`
Auth AuthConfig `yaml:"auth,omitempty"`
CustomDashboards dashboards.MonitoringDashboardsList `yaml:"custom_dashboards,omitempty"`
Deployment DeploymentConfig `yaml:"deployment,omitempty"`
ExternalServices ExternalServices `yaml:"external_services,omitempty"`
HealthConfig HealthConfig `yaml:"health_config,omitempty" json:"healthConfig,omitempty"`
Identity security.Identity `yaml:",omitempty"`
InCluster bool `yaml:"in_cluster,omitempty"`
InstallationTag string `yaml:"installation_tag,omitempty"`
IstioLabels IstioLabels `yaml:"istio_labels,omitempty"`
IstioNamespace string `yaml:"istio_namespace,omitempty"` // default component namespace
KialiFeatureFlags KialiFeatureFlags `yaml:"kiali_feature_flags,omitempty"`
KubernetesConfig KubernetesConfig `yaml:"kubernetes_config,omitempty"`
LoginToken LoginToken `yaml:"login_token,omitempty"`
Server Server `yaml:",omitempty"`
}
// NewConfig creates a default Config struct
func NewConfig() (c *Config) {
c = &Config{
InCluster: true,
IstioNamespace: "istio-system",
API: ApiConfig{
Namespaces: ApiNamespacesConfig{
Exclude: []string{
"^istio-operator",
"^kube-.*",
"^openshift.*",
"^ibm.*",
"^kial-operator",
},
Include: []string{},
LabelSelectorExclude: "",
},
},
Auth: AuthConfig{
Strategy: "token",
OpenId: OpenIdConfig{
AdditionalRequestParams: map[string]string{},
AllowedDomains: []string{},
ApiProxy: "",
ApiProxyCAData: "",
ApiToken: "id_token",
AuthenticationTimeout: 300,
AuthorizationEndpoint: "",
ClientId: "",
ClientSecret: "",
DisableRBAC: false,
InsecureSkipVerifyTLS: false,
IssuerUri: "",
Scopes: []string{"openid", "profile", "email"},
UsernameClaim: "sub",
},
OpenShift: OpenShiftConfig{
AuthTimeout: 10,
ClientIdPrefix: "kiali",
ServerPrefix: "https://kubernetes.default.svc/",
},
},
CustomDashboards: dashboards.GetBuiltInMonitoringDashboards(),
Deployment: DeploymentConfig{
AccessibleNamespaces: []string{"**"},
ClusterWideAccess: true,
InstanceName: "kiali",
Namespace: "istio-system",
RemoteSecretPath: "/kiali-remote-secret/kiali",
ViewOnlyMode: false,
},
ExternalServices: ExternalServices{
CustomDashboards: CustomDashboardsConfig{
DiscoveryEnabled: DashboardsDiscoveryAuto,
DiscoveryAutoThreshold: 10,
Enabled: true,
IsCore: false,
NamespaceLabel: "namespace",
Prometheus: PrometheusConfig{
ThanosProxy: ThanosProxy{
Enabled: false,
},
},
},
Grafana: GrafanaConfig{
Auth: Auth{
Type: AuthTypeNone,
},
Enabled: true,
InClusterURL: "http://grafana.istio-system:3000",
IsCore: false,
},
Istio: IstioConfig{
ComponentStatuses: ComponentStatuses{
Enabled: true,
Components: []ComponentStatus{
{
AppLabel: "istio-egressgateway",
IsCore: false,
IsProxy: true,
},
{
AppLabel: "istio-ingressgateway",
IsCore: true,
IsProxy: true,
},
{
AppLabel: "istiod",
IsCore: true,
IsProxy: false,
},
},
},
ConfigMapName: "istio",
EnvoyAdminLocalPort: 15000,
IstioAPIEnabled: true,
IstioIdentityDomain: "svc.cluster.local",
IstioInjectionAnnotation: "sidecar.istio.io/inject",
IstioSidecarInjectorConfigMapName: "istio-sidecar-injector",
IstioSidecarAnnotation: "sidecar.istio.io/status",
IstiodDeploymentName: "istiod",
IstiodPodMonitoringPort: 15014,
IstiodPollingIntervalSeconds: 20,
RootNamespace: "istio-system",
UrlServiceVersion: "http://istiod.istio-system:15014/version",
GatewayAPIClasses: []GatewayAPIClass{
{
Name: "Istio", ClassName: "istio",
},
},
},
Prometheus: PrometheusConfig{
Auth: Auth{
Type: AuthTypeNone,
},
// 1/2 Prom Scrape Interval
CacheDuration: 7,
CacheEnabled: true,
// Prom Cache expires and it forces to repopulate cache
CacheExpiration: 300,
CustomHeaders: map[string]string{},
QueryScope: map[string]string{},
ThanosProxy: ThanosProxy{
Enabled: false,
RetentionPeriod: "7d",
ScrapeInterval: "30s",
},
URL: "http://prometheus.istio-system:9090",
},
Tracing: TracingConfig{
Auth: Auth{
Type: AuthTypeNone,
},
Enabled: true,
GrpcPort: 9095,
InClusterURL: "http://tracing.istio-system:16685/jaeger",
IsCore: false,
Provider: "jaeger",
NamespaceSelector: true,
QueryScope: map[string]string{},
QueryTimeout: 5,
URL: "",
UseGRPC: true,
WhiteListIstioSystem: []string{"jaeger-query", "istio-ingressgateway"},
},
},
IstioLabels: IstioLabels{
AmbientNamespaceLabel: "istio.io/dataplane-mode",
AmbientNamespaceLabelValue: "ambient",
AmbientWaypointLabel: WaypointLabel,
AmbientWaypointLabelValue: WaypointLabelValue,
AppLabelName: "app",
InjectionLabelName: "istio-injection",
InjectionLabelRev: "istio.io/rev",
VersionLabelName: "version",
},
KialiFeatureFlags: KialiFeatureFlags{
CertificatesInformationIndicators: CertificatesInformationIndicators{
Enabled: true,
Secrets: []string{"cacerts", "istio-ca-secret"},
},
Clustering: Clustering{
EnableExecProvider: false,
},
DisabledFeatures: []string{},
IstioAnnotationAction: true,
IstioInjectionAction: true,
IstioUpgradeAction: false,
UIDefaults: UIDefaults{
Graph: GraphUIDefaults{
FindOptions: []GraphFindOption{
{
Description: "Find: slow edges (> 1s)",
Expression: "rt > 1000",
},
{
Description: "Find: unhealthy nodes",
Expression: "! healthy",
},
{
Description: "Find: unknown nodes",
Expression: "name = unknown",
},
{
Description: "Find: nodes with the 2 top rankings",
Expression: "rank <= 2",
},
},
HideOptions: []GraphFindOption{
{
Description: "Hide: healthy nodes",
Expression: "healthy",
},
{
Description: "Hide: unknown nodes",
Expression: "name = unknown",
},
{
Description: "Hide: nodes ranked lower than the 2 top rankings",
Expression: "rank > 2",
},
},
Impl: "cy",
Settings: GraphSettings{
FontLabel: 13,
MinFontBadge: 7,
MinFontLabel: 10,
},
Traffic: GraphTraffic{
Grpc: "requests",
Http: "requests",
Tcp: "sent",
},
},
List: ListUIDefaults{
IncludeHealth: true,
IncludeIstioResources: true,
IncludeValidations: true,
ShowIncludeToggles: false,
},
MetricsInbound: MetricsDefaults{},
MetricsOutbound: MetricsDefaults{},
MetricsPerRefresh: "1m",
Namespaces: make([]string, 0),
RefreshInterval: "60s",
},
Validations: Validations{
Ignore: make([]string, 0),
},
},
KubernetesConfig: KubernetesConfig{
Burst: 200,
CacheDuration: 5 * 60,
CacheTokenNamespaceDuration: 10,
ClusterName: "", // leave this unset as a flag that we need to fetch the information
ExcludeWorkloads: []string{"CronJob", "DeploymentConfig", "Job", "ReplicationController"},
QPS: 175,
},
LoginToken: LoginToken{
ExpirationSeconds: 24 * 3600,
SigningKey: "kiali",
},
Server: Server{
AuditLog: true,
GzipEnabled: true,
Observability: Observability{
Metrics: Metrics{
Enabled: true,
Port: 9090,
},
Tracing: Tracing{
CollectorType: "jaeger",
CollectorURL: "http://jaeger-collector.istio-system:14268/api/traces",
Enabled: false,
Otel: OtelCollector{
CAName: "",
Protocol: "http",
SkipVerify: true,
TLSEnabled: false,
},
// Sample half of traces.
SamplingRate: 0.5,
},
},
Port: 20001,
StaticContentRootDirectory: "/opt/kiali/console",
WebFQDN: "",
WebRoot: "/",
WebHistoryMode: "browser",
WebSchema: "",
},
}
return
}
// AddHealthDefault Configuration
func (conf *Config) AddHealthDefault() {
// Health default configuration
healthConfig := HealthConfig{
Rate: []Rate{
{
Tolerance: []Tolerance{
{
Code: "5XX",
Protocol: "http",
Direction: ".*",
Failure: 10,
},
{
Code: "4XX",
Protocol: "http",
Direction: ".*",
Degraded: 10,
Failure: 20,
},
{
Code: "^[1-9]$|^1[0-6]$",
Protocol: "grpc",
Direction: ".*",
Failure: 10,
},
{
Code: "^-$", // no response is indicated with a "-" code
Protocol: "http|grpc",
Direction: ".*",
Failure: 10,
},
},
},
},
}
conf.HealthConfig.Rate = append(conf.HealthConfig.Rate, healthConfig.Rate...)
}
// AllNamespacesAccessible determines if kiali has access to all namespaces.
// When using the operator, the operator will grant the kiali service account
// cluster role permissions when '**' is provided in the accessible_namespaces
// or if cluster-wide-access was explicitly requested.
func (conf *Config) AllNamespacesAccessible() bool {
// look for ** in accessible namespaces first, as we have done in the past. This backwards compatible
// behavior will help support users who installed the server via the server helm chart.
for _, ns := range conf.Deployment.AccessibleNamespaces {
if ns == "**" {
return true
}
}
// it is still possible we are in cluster wide access mode even if accessible namespaces has been restricted
return conf.Deployment.ClusterWideAccess
}
// IsServerHttps returns true if the server endpoint should use HTTPS. If false, only plaintext HTTP is supported.
func (conf *Config) IsServerHttps() bool {
return conf.Identity.CertFile != "" && conf.Identity.PrivateKeyFile != ""
}
// Get the global Config
func Get() (conf *Config) {
rwMutex.RLock()
defer rwMutex.RUnlock()
copy := configuration
return ©
}
// Set the global Config
// This function should not be called outside of main or tests.
// If possible keep config unmutated and use globals and/or appstate package for mutable states to avoid concurrent writes risk.
func Set(conf *Config) {
rwMutex.Lock()
defer rwMutex.Unlock()
conf.AddHealthDefault()
configuration = *conf
}
// String marshals the given Config into a YAML string
// WARNING: do NOT use the result of this function to retrieve any configuration: some fields are obfuscated for security reasons.
func (conf Config) String() (str string) {
obf := conf
obf.ExternalServices.Grafana.Auth.Obfuscate()
obf.ExternalServices.Prometheus.Auth.Obfuscate()
obf.ExternalServices.Tracing.Auth.Obfuscate()
obf.Identity.Obfuscate()
obf.LoginToken.Obfuscate()
obf.Auth.OpenId.ClientSecret = "xxx"
str, err := Marshal(&obf)
if err != nil {
str = fmt.Sprintf("Failed to marshal config to string. err=%v", err)
log.Debugf(str)
}
return
}
// prepareDashboards will ensure conf.CustomDashboards contains only the dashboards that are enabled
func (conf *Config) prepareDashboards() {
if conf.ExternalServices.CustomDashboards.Enabled {
// If the user defined their own dashboards, we still want the built-in dashboards as a fallback.
// But the user-defined dashboards take precedence - if they gave us dashboards with the same name
// as one of the built-in dashboards, the user-defined dashboard "wins".
conf.CustomDashboards = dashboards.AddMonitoringDashboards(dashboards.GetBuiltInMonitoringDashboards(), conf.CustomDashboards)
} else {
// The user has disabled the custom dashboards, empty out the list completely
conf.CustomDashboards = dashboards.MonitoringDashboardsList(make([]dashboards.MonitoringDashboard, 0))
}
// to assist in debugging problems, log the number of dashboards and their names
if log.IsDebug() {
dashboardNames := make([]string, 0, len(conf.CustomDashboards))
for _, d := range conf.CustomDashboards {
dashboardNames = append(dashboardNames, d.Name)
}
sort.Strings(dashboardNames)
log.Debugf("Custom dashboards [count=%v, enabled=%v]: %v", len(dashboardNames), conf.ExternalServices.CustomDashboards.Enabled, strings.Join(dashboardNames, ","))
}
}
// Unmarshal parses the given YAML string and returns its Config object representation.
func Unmarshal(yamlString string) (conf *Config, err error) {
conf = NewConfig()
err = yaml.Unmarshal([]byte(yamlString), &conf)
if err != nil {
return nil, fmt.Errorf("failed to parse yaml data. error=%v", err)
}
conf.prepareDashboards()
// Some config settings (such as sensitive settings like passwords) are overrideable
// via secrets mounted on the file system rather than storing them directly in the config map itself.
// The names of the files in /kiali-override-secrets denote which credentials they are.
type overridesType struct {
configValue *string
fileName string
}
overrides := []overridesType{
{
configValue: &conf.ExternalServices.Grafana.Auth.Password,
fileName: SecretFileGrafanaPassword,
},
{
configValue: &conf.ExternalServices.Grafana.Auth.Token,
fileName: SecretFileGrafanaToken,
},
{
configValue: &conf.ExternalServices.Prometheus.Auth.Password,
fileName: SecretFilePrometheusPassword,
},
{
configValue: &conf.ExternalServices.Prometheus.Auth.Token,
fileName: SecretFilePrometheusToken,
},
{
configValue: &conf.ExternalServices.Tracing.Auth.Password,
fileName: SecretFileTracingPassword,
},
{
configValue: &conf.ExternalServices.Tracing.Auth.Token,
fileName: SecretFileTracingToken,
},
{
configValue: &conf.LoginToken.SigningKey,
fileName: SecretFileLoginTokenSigningKey,
},
}
for _, override := range overrides {
fullFileName := overrideSecretsDir + "/" + override.fileName + "/value.txt"
b, err := os.ReadFile(fullFileName)
if err == nil {
fileContents := string(b)
if fileContents != "" {
*override.configValue = fileContents