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{
63 "API.AsyncPermissionsUpdateInterval": false,
64 "API.DisabledAPIs": false,
65 "API.KeepServiceRequestTimeout": 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.MaxTokenLifetime": false,
73 "API.RequestTimeout": true,
74 "API.SendTimeout": true,
75 "API.WebsocketClientEventQueue": false,
76 "API.WebsocketServerEventQueue": false,
78 "AuditLogs.MaxAge": false,
79 "AuditLogs.MaxDeleteBatch": false,
80 "AuditLogs.UnloggedAttributes": false,
83 "Collections.BalanceCollectionBatch": false,
84 "Collections.BalanceCollectionBuffers": false,
85 "Collections.BalancePeriod": false,
86 "Collections.BalanceTimeout": false,
87 "Collections.BlobDeleteConcurrency": false,
88 "Collections.BlobMissingReport": false,
89 "Collections.BlobReplicateConcurrency": false,
90 "Collections.BlobSigning": true,
91 "Collections.BlobSigningKey": false,
92 "Collections.BlobSigningTTL": true,
93 "Collections.BlobTrash": false,
94 "Collections.BlobTrashCheckInterval": false,
95 "Collections.BlobTrashConcurrency": false,
96 "Collections.BlobTrashLifetime": false,
97 "Collections.CollectionVersioning": false,
98 "Collections.DefaultReplication": true,
99 "Collections.DefaultTrashLifetime": true,
100 "Collections.ForwardSlashNameSubstitution": true,
101 "Collections.ManagedProperties": true,
102 "Collections.ManagedProperties.*": true,
103 "Collections.ManagedProperties.*.*": true,
104 "Collections.PreserveVersionIfIdle": true,
105 "Collections.S3FolderObjects": true,
106 "Collections.TrashSweepInterval": false,
107 "Collections.TrustAllContent": false,
108 "Collections.WebDAVCache": false,
110 "Containers.CloudVMs": false,
111 "Containers.CrunchRunArgumentsList": false,
112 "Containers.CrunchRunCommand": false,
113 "Containers.DefaultKeepCacheRAM": true,
114 "Containers.DispatchPrivateKey": false,
115 "Containers.JobsAPI": true,
116 "Containers.JobsAPI.Enable": true,
117 "Containers.JobsAPI.GitInternalDir": false,
118 "Containers.Logging": false,
119 "Containers.LogReuseDecisions": false,
120 "Containers.MaxComputeVMs": false,
121 "Containers.MaxDispatchAttempts": false,
122 "Containers.MaxRetryAttempts": true,
123 "Containers.MinRetryPeriod": true,
124 "Containers.ReserveExtraRAM": true,
125 "Containers.ShellAccess": true,
126 "Containers.ShellAccess.Admin": true,
127 "Containers.ShellAccess.User": true,
128 "Containers.SLURM": false,
129 "Containers.StaleLockTimeout": false,
130 "Containers.SupportedDockerImageFormats": true,
131 "Containers.SupportedDockerImageFormats.*": true,
132 "Containers.UsePreemptibleInstances": true,
134 "InstanceTypes": true,
135 "InstanceTypes.*": true,
136 "InstanceTypes.*.*": true,
138 "Login.Google": true,
139 "Login.Google.AlternateEmailAddresses": false,
140 "Login.Google.AuthenticationRequestParameters": false,
141 "Login.Google.ClientID": false,
142 "Login.Google.ClientSecret": false,
143 "Login.Google.Enable": true,
145 "Login.LDAP.AppendDomain": false,
146 "Login.LDAP.EmailAttribute": false,
147 "Login.LDAP.Enable": true,
148 "Login.LDAP.InsecureTLS": false,
149 "Login.LDAP.SearchAttribute": false,
150 "Login.LDAP.SearchBase": false,
151 "Login.LDAP.SearchBindPassword": false,
152 "Login.LDAP.SearchBindUser": false,
153 "Login.LDAP.SearchFilters": false,
154 "Login.LDAP.StartTLS": false,
155 "Login.LDAP.StripDomain": false,
156 "Login.LDAP.URL": false,
157 "Login.LDAP.UsernameAttribute": false,
158 "Login.LoginCluster": true,
159 "Login.OpenIDConnect": true,
160 "Login.OpenIDConnect.AuthenticationRequestParameters": false,
161 "Login.OpenIDConnect.ClientID": false,
162 "Login.OpenIDConnect.ClientSecret": false,
163 "Login.OpenIDConnect.EmailClaim": false,
164 "Login.OpenIDConnect.EmailVerifiedClaim": false,
165 "Login.OpenIDConnect.Enable": true,
166 "Login.OpenIDConnect.Issuer": false,
167 "Login.OpenIDConnect.UsernameClaim": false,
169 "Login.PAM.DefaultEmailDomain": false,
170 "Login.PAM.Enable": true,
171 "Login.PAM.Service": false,
172 "Login.RemoteTokenRefresh": true,
174 "Login.SSO.Enable": true,
175 "Login.SSO.ProviderAppID": false,
176 "Login.SSO.ProviderAppSecret": false,
178 "Login.Test.Enable": true,
179 "Login.Test.Users": false,
180 "Login.TokenLifetime": false,
181 "Login.TrustedClients": false,
183 "Mail.EmailFrom": false,
184 "Mail.IssueReporterEmailFrom": false,
185 "Mail.IssueReporterEmailTo": false,
186 "Mail.MailchimpAPIKey": false,
187 "Mail.MailchimpListID": false,
188 "Mail.SendUserSetupNotificationEmail": false,
189 "Mail.SupportEmailAddress": true,
190 "ManagementToken": false,
192 "RemoteClusters": true,
193 "RemoteClusters.*": true,
194 "RemoteClusters.*.ActivateUsers": true,
195 "RemoteClusters.*.Host": true,
196 "RemoteClusters.*.Insecure": true,
197 "RemoteClusters.*.Proxy": true,
198 "RemoteClusters.*.Scheme": true,
201 "Services.*.ExternalURL": true,
202 "Services.*.InternalURLs": false,
204 "SystemRootToken": false,
207 "Users.AdminNotifierEmailFrom": false,
208 "Users.AnonymousUserToken": true,
209 "Users.AutoAdminFirstUser": false,
210 "Users.AutoAdminUserWithEmail": false,
211 "Users.AutoSetupNewUsers": false,
212 "Users.AutoSetupNewUsersWithRepository": false,
213 "Users.AutoSetupNewUsersWithVmUUID": false,
214 "Users.AutoSetupUsernameBlacklist": false,
215 "Users.EmailSubjectPrefix": false,
216 "Users.NewInactiveUserNotificationRecipients": false,
217 "Users.NewUserNotificationRecipients": false,
218 "Users.NewUsersAreActive": false,
219 "Users.PreferDomainForUsername": false,
220 "Users.UserNotifierEmailFrom": false,
221 "Users.UserProfileNotificationAddress": false,
222 "Users.UserSetupMailText": false,
225 "Volumes.*.*": false,
226 "Volumes.*.AccessViaHosts": true,
227 "Volumes.*.AccessViaHosts.*": true,
228 "Volumes.*.AccessViaHosts.*.ReadOnly": true,
229 "Volumes.*.ReadOnly": true,
230 "Volumes.*.Replication": true,
231 "Volumes.*.StorageClasses": true,
232 "Volumes.*.StorageClasses.*": false,
234 "Workbench.ActivationContactLink": false,
235 "Workbench.APIClientConnectTimeout": true,
236 "Workbench.APIClientReceiveTimeout": true,
237 "Workbench.APIResponseCompression": true,
238 "Workbench.ApplicationMimetypesWithViewIcon": true,
239 "Workbench.ApplicationMimetypesWithViewIcon.*": true,
240 "Workbench.ArvadosDocsite": true,
241 "Workbench.ArvadosPublicDataDocURL": true,
242 "Workbench.DefaultOpenIdPrefix": false,
243 "Workbench.EnableGettingStartedPopup": true,
244 "Workbench.EnablePublicProjectsPage": true,
245 "Workbench.FileViewersConfigURL": true,
246 "Workbench.IdleTimeout": true,
247 "Workbench.InactivePageHTML": true,
248 "Workbench.LogViewerMaxBytes": true,
249 "Workbench.MultiSiteSearch": true,
250 "Workbench.ProfilingEnabled": true,
251 "Workbench.Repositories": false,
252 "Workbench.RepositoryCache": false,
253 "Workbench.RunningJobLogRecordsToFetch": true,
254 "Workbench.SecretKeyBase": false,
255 "Workbench.ShowRecentCollectionsOnDashboard": true,
256 "Workbench.ShowUserAgreementInline": true,
257 "Workbench.ShowUserNotifications": true,
258 "Workbench.SiteName": true,
259 "Workbench.SSHHelpHostSuffix": true,
260 "Workbench.SSHHelpPageHTML": true,
261 "Workbench.Theme": true,
262 "Workbench.UserProfileFormFields": true,
263 "Workbench.UserProfileFormFields.*": true,
264 "Workbench.UserProfileFormFields.*.*": true,
265 "Workbench.UserProfileFormFields.*.*.*": true,
266 "Workbench.UserProfileFormMessage": true,
267 "Workbench.VocabularyURL": true,
268 "Workbench.WelcomePageHTML": true,
271 func redactUnsafe(m map[string]interface{}, mPrefix, lookupPrefix string) error {
273 for k, v := range m {
275 safe, ok := whitelist[lookupPrefix+k]
278 safe, ok = whitelist[lookupPrefix+"*"]
281 errs = append(errs, fmt.Sprintf("config bug: key %q not in whitelist map", lookupPrefix+k))
288 if v, ok := v.(map[string]interface{}); ok {
289 err := redactUnsafe(v, mPrefix+k+".", lookupPrefix+lookupKey+".")
291 errs = append(errs, err.Error())
296 return errors.New(strings.Join(errs, "\n"))