1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.arvados.org/arvados.git/sdk/go/arvados"
17 // ExportJSON writes a JSON object with the safe (non-secret) portions
18 // of the cluster config to w.
19 func ExportJSON(w io.Writer, cluster *arvados.Cluster) error {
20 buf, err := json.Marshal(cluster)
24 var m map[string]interface{}
25 err = json.Unmarshal(buf, &m)
30 // ClusterID is not marshalled by default (see `json:"-"`).
31 // Add it back here so it is included in the exported config.
32 m["ClusterID"] = cluster.ClusterID
33 err = redactUnsafe(m, "", "")
37 return json.NewEncoder(w).Encode(m)
40 // whitelist classifies configs as safe/unsafe to reveal to
41 // unauthenticated clients.
43 // Every config entry must either be listed explicitly here along with
44 // all of its parent keys (e.g., "API" + "API.RequestTimeout"), or
45 // have an ancestor listed as false (e.g.,
46 // "PostgreSQL.Connection.password" has an ancestor
47 // "PostgreSQL.Connection" with a false value). Otherwise, it is a bug
48 // which should be caught by tests.
50 // Example: API.RequestTimeout is safe because whitelist["API"] == and
51 // whitelist["API.RequestTimeout"] == true.
53 // Example: PostgreSQL.Connection.password is not safe because
54 // whitelist["PostgreSQL.Connection"] == false.
56 // Example: PostgreSQL.BadKey would cause an error because
57 // whitelist["PostgreSQL"] isn't false, and neither
58 // whitelist["PostgreSQL.BadKey"] nor whitelist["PostgreSQL.*"]
60 var whitelist = map[string]bool{
64 "API.AsyncPermissionsUpdateInterval": false,
65 "API.DisabledAPIs": false,
66 "API.MaxConcurrentRequests": false,
67 "API.MaxIndexDatabaseRead": false,
68 "API.MaxItemsPerResponse": true,
69 "API.MaxKeepBlobBuffers": false,
70 "API.MaxRequestAmplification": false,
71 "API.MaxRequestSize": true,
72 "API.RailsSessionSecretToken": false,
73 "API.RequestTimeout": true,
74 "API.WebsocketClientEventQueue": false,
75 "API.SendTimeout": true,
76 "API.WebsocketServerEventQueue": false,
77 "API.KeepServiceRequestTimeout": false,
79 "AuditLogs.MaxAge": false,
80 "AuditLogs.MaxDeleteBatch": false,
81 "AuditLogs.UnloggedAttributes": false,
83 "Collections.BlobSigning": true,
84 "Collections.BlobSigningKey": false,
85 "Collections.BlobSigningTTL": true,
86 "Collections.BlobTrash": false,
87 "Collections.BlobTrashLifetime": false,
88 "Collections.BlobTrashConcurrency": false,
89 "Collections.BlobTrashCheckInterval": false,
90 "Collections.BlobDeleteConcurrency": false,
91 "Collections.BlobReplicateConcurrency": false,
92 "Collections.CollectionVersioning": false,
93 "Collections.DefaultReplication": true,
94 "Collections.DefaultTrashLifetime": true,
95 "Collections.ForwardSlashNameSubstitution": true,
96 "Collections.ManagedProperties": true,
97 "Collections.ManagedProperties.*": true,
98 "Collections.ManagedProperties.*.*": true,
99 "Collections.PreserveVersionIfIdle": true,
100 "Collections.TrashSweepInterval": false,
101 "Collections.TrustAllContent": false,
102 "Collections.WebDAVCache": false,
103 "Collections.BalanceCollectionBatch": false,
104 "Collections.BalancePeriod": false,
105 "Collections.BlobMissingReport": false,
106 "Collections.BalanceCollectionBuffers": false,
108 "Containers.CloudVMs": false,
109 "Containers.CrunchRunCommand": false,
110 "Containers.CrunchRunArgumentsList": false,
111 "Containers.DefaultKeepCacheRAM": true,
112 "Containers.DispatchPrivateKey": false,
113 "Containers.JobsAPI": true,
114 "Containers.JobsAPI.Enable": true,
115 "Containers.JobsAPI.GitInternalDir": false,
116 "Containers.Logging": false,
117 "Containers.LogReuseDecisions": false,
118 "Containers.MaxComputeVMs": false,
119 "Containers.MaxDispatchAttempts": false,
120 "Containers.MaxRetryAttempts": true,
121 "Containers.MinRetryPeriod": true,
122 "Containers.ReserveExtraRAM": true,
123 "Containers.SLURM": false,
124 "Containers.StaleLockTimeout": false,
125 "Containers.SupportedDockerImageFormats": true,
126 "Containers.SupportedDockerImageFormats.*": true,
127 "Containers.UsePreemptibleInstances": true,
128 "ForceLegacyAPI14": false,
130 "InstanceTypes": true,
131 "InstanceTypes.*": true,
132 "InstanceTypes.*.*": true,
134 "Login.Google": true,
135 "Login.Google.AlternateEmailAddresses": false,
136 "Login.Google.ClientID": false,
137 "Login.Google.ClientSecret": false,
138 "Login.Google.Enable": true,
140 "Login.LDAP.AppendDomain": false,
141 "Login.LDAP.EmailAttribute": false,
142 "Login.LDAP.Enable": true,
143 "Login.LDAP.InsecureTLS": false,
144 "Login.LDAP.SearchAttribute": false,
145 "Login.LDAP.SearchBase": false,
146 "Login.LDAP.SearchBindPassword": false,
147 "Login.LDAP.SearchBindUser": false,
148 "Login.LDAP.SearchFilters": false,
149 "Login.LDAP.StartTLS": false,
150 "Login.LDAP.StripDomain": false,
151 "Login.LDAP.URL": false,
152 "Login.LDAP.UsernameAttribute": false,
153 "Login.LoginCluster": true,
154 "Login.OpenIDConnect": true,
155 "Login.OpenIDConnect.ClientID": false,
156 "Login.OpenIDConnect.ClientSecret": false,
157 "Login.OpenIDConnect.Enable": true,
158 "Login.OpenIDConnect.Issuer": false,
159 "Login.OpenIDConnect.EmailClaim": false,
160 "Login.OpenIDConnect.EmailVerifiedClaim": false,
161 "Login.OpenIDConnect.UsernameClaim": false,
163 "Login.PAM.DefaultEmailDomain": false,
164 "Login.PAM.Enable": true,
165 "Login.PAM.Service": false,
167 "Login.SSO.Enable": true,
168 "Login.SSO.ProviderAppID": false,
169 "Login.SSO.ProviderAppSecret": false,
170 "Login.RemoteTokenRefresh": true,
172 "Mail.MailchimpAPIKey": false,
173 "Mail.MailchimpListID": false,
174 "Mail.SendUserSetupNotificationEmail": false,
175 "Mail.IssueReporterEmailFrom": false,
176 "Mail.IssueReporterEmailTo": false,
177 "Mail.SupportEmailAddress": true,
178 "Mail.EmailFrom": false,
179 "ManagementToken": false,
181 "RemoteClusters": true,
182 "RemoteClusters.*": true,
183 "RemoteClusters.*.ActivateUsers": true,
184 "RemoteClusters.*.Host": true,
185 "RemoteClusters.*.Insecure": true,
186 "RemoteClusters.*.Proxy": true,
187 "RemoteClusters.*.Scheme": true,
190 "Services.*.ExternalURL": true,
191 "Services.*.InternalURLs": false,
193 "SystemRootToken": false,
196 "Users.AnonymousUserToken": true,
197 "Users.AdminNotifierEmailFrom": false,
198 "Users.AutoAdminFirstUser": false,
199 "Users.AutoAdminUserWithEmail": false,
200 "Users.AutoSetupNewUsers": false,
201 "Users.AutoSetupNewUsersWithRepository": false,
202 "Users.AutoSetupNewUsersWithVmUUID": false,
203 "Users.AutoSetupUsernameBlacklist": false,
204 "Users.EmailSubjectPrefix": false,
205 "Users.NewInactiveUserNotificationRecipients": false,
206 "Users.NewUserNotificationRecipients": false,
207 "Users.NewUsersAreActive": false,
208 "Users.PreferDomainForUsername": false,
209 "Users.UserNotifierEmailFrom": false,
210 "Users.UserProfileNotificationAddress": false,
213 "Volumes.*.*": false,
214 "Volumes.*.AccessViaHosts": true,
215 "Volumes.*.AccessViaHosts.*": true,
216 "Volumes.*.AccessViaHosts.*.ReadOnly": true,
217 "Volumes.*.ReadOnly": true,
218 "Volumes.*.Replication": true,
219 "Volumes.*.StorageClasses": true,
220 "Volumes.*.StorageClasses.*": false,
222 "Workbench.ActivationContactLink": false,
223 "Workbench.APIClientConnectTimeout": true,
224 "Workbench.APIClientReceiveTimeout": true,
225 "Workbench.APIResponseCompression": true,
226 "Workbench.ApplicationMimetypesWithViewIcon": true,
227 "Workbench.ApplicationMimetypesWithViewIcon.*": true,
228 "Workbench.ArvadosDocsite": true,
229 "Workbench.ArvadosPublicDataDocURL": true,
230 "Workbench.DefaultOpenIdPrefix": false,
231 "Workbench.EnableGettingStartedPopup": true,
232 "Workbench.EnablePublicProjectsPage": true,
233 "Workbench.FileViewersConfigURL": true,
234 "Workbench.LogViewerMaxBytes": true,
235 "Workbench.MultiSiteSearch": true,
236 "Workbench.ProfilingEnabled": true,
237 "Workbench.Repositories": false,
238 "Workbench.RepositoryCache": false,
239 "Workbench.RunningJobLogRecordsToFetch": true,
240 "Workbench.SecretKeyBase": false,
241 "Workbench.ShowRecentCollectionsOnDashboard": true,
242 "Workbench.ShowUserAgreementInline": true,
243 "Workbench.ShowUserNotifications": true,
244 "Workbench.SiteName": true,
245 "Workbench.Theme": true,
246 "Workbench.UserProfileFormFields": true,
247 "Workbench.UserProfileFormFields.*": true,
248 "Workbench.UserProfileFormFields.*.*": true,
249 "Workbench.UserProfileFormFields.*.*.*": true,
250 "Workbench.UserProfileFormMessage": true,
251 "Workbench.VocabularyURL": true,
252 "Workbench.WelcomePageHTML": true,
253 "Workbench.InactivePageHTML": true,
254 "Workbench.SSHHelpPageHTML": true,
255 "Workbench.SSHHelpHostSuffix": true,
258 func redactUnsafe(m map[string]interface{}, mPrefix, lookupPrefix string) error {
260 for k, v := range m {
262 safe, ok := whitelist[lookupPrefix+k]
265 safe, ok = whitelist[lookupPrefix+"*"]
268 errs = append(errs, fmt.Sprintf("config bug: key %q not in whitelist map", lookupPrefix+k))
275 if v, ok := v.(map[string]interface{}); ok {
276 err := redactUnsafe(v, mPrefix+k+".", lookupPrefix+lookupKey+".")
278 errs = append(errs, err.Error())
283 return errors.New(strings.Join(errs, "\n"))