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 through the API
41 // endpoint. Note that endpoint does not require authentication.
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.FreezeProjectRequiresDescription": true,
66 "API.FreezeProjectRequiresProperties": true,
67 "API.FreezeProjectRequiresProperties.*": true,
68 "API.KeepServiceRequestTimeout": false,
69 "API.LockBeforeUpdate": false,
70 "API.MaxConcurrentRailsRequests": false,
71 "API.MaxConcurrentRequests": false,
72 "API.MaxGatewayTunnels": false,
73 "API.MaxIndexDatabaseRead": false,
74 "API.MaxItemsPerResponse": true,
75 "API.MaxKeepBlobBuffers": false,
76 "API.MaxQueuedRequests": false,
77 "API.MaxQueueTimeForLockRequests": false,
78 "API.MaxRequestAmplification": false,
79 "API.MaxRequestSize": true,
80 "API.MaxTokenLifetime": false,
81 "API.RequestTimeout": true,
82 "API.SendTimeout": true,
83 "API.UnfreezeProjectRequiresAdmin": true,
84 "API.VocabularyPath": false,
85 "API.WebsocketClientEventQueue": false,
86 "API.WebsocketServerEventQueue": false,
88 "AuditLogs.MaxAge": false,
89 "AuditLogs.MaxDeleteBatch": false,
90 "AuditLogs.UnloggedAttributes": false,
93 "Collections.BalanceCollectionBatch": false,
94 "Collections.BalanceCollectionBuffers": false,
95 "Collections.BalancePeriod": false,
96 "Collections.BalancePullLimit": false,
97 "Collections.BalanceTimeout": false,
98 "Collections.BalanceTrashLimit": false,
99 "Collections.BalanceUpdateLimit": false,
100 "Collections.BlobDeleteConcurrency": false,
101 "Collections.BlobMissingReport": false,
102 "Collections.BlobReplicateConcurrency": false,
103 "Collections.BlobSigning": true,
104 "Collections.BlobSigningKey": false,
105 "Collections.BlobSigningTTL": true,
106 "Collections.BlobTrash": false,
107 "Collections.BlobTrashCheckInterval": false,
108 "Collections.BlobTrashConcurrency": false,
109 "Collections.BlobTrashLifetime": false,
110 "Collections.CollectionVersioning": true,
111 "Collections.DefaultReplication": true,
112 "Collections.DefaultTrashLifetime": true,
113 "Collections.ForwardSlashNameSubstitution": true,
114 "Collections.KeepproxyPermission": false,
115 "Collections.ManagedProperties": true,
116 "Collections.ManagedProperties.*": true,
117 "Collections.ManagedProperties.*.*": true,
118 "Collections.PreserveVersionIfIdle": true,
119 "Collections.S3FolderObjects": true,
120 "Collections.TrashSweepInterval": false,
121 "Collections.TrustAllContent": true,
122 "Collections.WebDAVCache": false,
123 "Collections.WebDAVLogEvents": false,
124 "Collections.WebDAVLogDownloadInterval": false,
125 "Collections.WebDAVOutputBuffer": false,
126 "Collections.WebDAVPermission": false,
128 "Containers.AlwaysUsePreemptibleInstances": true,
129 "Containers.CloudVMs": false,
130 "Containers.CrunchRunArgumentsList": false,
131 "Containers.CrunchRunCommand": false,
132 "Containers.DefaultKeepCacheRAM": true,
133 "Containers.DispatchPrivateKey": false,
134 "Containers.LocalKeepBlobBuffersPerVCPU": false,
135 "Containers.LocalKeepLogsToContainerLog": false,
136 "Containers.Logging": false,
137 "Containers.LogReuseDecisions": false,
138 "Containers.LSF": false,
139 "Containers.MaxDispatchAttempts": false,
140 "Containers.MaximumPriceFactor": true,
141 "Containers.MaxRetryAttempts": true,
142 "Containers.MinRetryPeriod": true,
143 "Containers.PreemptiblePriceFactor": false,
144 "Containers.ReserveExtraRAM": true,
145 "Containers.RuntimeEngine": true,
146 "Containers.ShellAccess": true,
147 "Containers.ShellAccess.Admin": true,
148 "Containers.ShellAccess.User": true,
149 "Containers.SLURM": false,
150 "Containers.StaleLockTimeout": false,
151 "Containers.SupportedDockerImageFormats": true,
152 "Containers.SupportedDockerImageFormats.*": true,
153 "InstanceTypes": true,
154 "InstanceTypes.*": true,
155 "InstanceTypes.*.*": true,
156 "InstanceTypes.*.*.*": true,
158 "Login.Google": true,
159 "Login.Google.AlternateEmailAddresses": false,
160 "Login.Google.AuthenticationRequestParameters": false,
161 "Login.Google.ClientID": false,
162 "Login.Google.ClientSecret": false,
163 "Login.Google.Enable": true,
164 "Login.IssueTrustedTokens": false,
166 "Login.LDAP.AppendDomain": false,
167 "Login.LDAP.EmailAttribute": false,
168 "Login.LDAP.Enable": true,
169 "Login.LDAP.InsecureTLS": false,
170 "Login.LDAP.MinTLSVersion": false,
171 "Login.LDAP.SearchAttribute": false,
172 "Login.LDAP.SearchBase": false,
173 "Login.LDAP.SearchBindPassword": false,
174 "Login.LDAP.SearchBindUser": false,
175 "Login.LDAP.SearchFilters": false,
176 "Login.LDAP.StartTLS": false,
177 "Login.LDAP.StripDomain": false,
178 "Login.LDAP.URL": false,
179 "Login.LDAP.UsernameAttribute": false,
180 "Login.LoginCluster": true,
181 "Login.OpenIDConnect": true,
182 "Login.OpenIDConnect.AcceptAccessToken": false,
183 "Login.OpenIDConnect.AcceptAccessTokenScope": false,
184 "Login.OpenIDConnect.AuthenticationRequestParameters": false,
185 "Login.OpenIDConnect.ClientID": false,
186 "Login.OpenIDConnect.ClientSecret": false,
187 "Login.OpenIDConnect.EmailClaim": false,
188 "Login.OpenIDConnect.EmailVerifiedClaim": false,
189 "Login.OpenIDConnect.Enable": true,
190 "Login.OpenIDConnect.Issuer": false,
191 "Login.OpenIDConnect.UsernameClaim": false,
193 "Login.PAM.DefaultEmailDomain": false,
194 "Login.PAM.Enable": true,
195 "Login.PAM.Service": false,
196 "Login.RemoteTokenRefresh": true,
198 "Login.Test.Enable": true,
199 "Login.Test.Users": false,
200 "Login.TokenLifetime": false,
201 "Login.TrustedClients": false,
202 "Login.TrustPrivateNetworks": false,
203 "ManagementToken": false,
205 "RemoteClusters": true,
206 "RemoteClusters.*": true,
207 "RemoteClusters.*.ActivateUsers": true,
208 "RemoteClusters.*.Host": true,
209 "RemoteClusters.*.Insecure": true,
210 "RemoteClusters.*.Proxy": true,
211 "RemoteClusters.*.Scheme": true,
214 "Services.*.ExternalURL": true,
215 "Services.*.InternalURLs": false,
216 "StorageClasses": true,
217 "StorageClasses.*": true,
218 "StorageClasses.*.Default": true,
219 "StorageClasses.*.Priority": true,
221 "SystemRootToken": false,
223 "TLS.Certificate": false,
224 "TLS.Insecure": true,
227 "Users.ActivatedUsersAreVisibleToOthers": false,
228 "Users.ActivityLoggingPeriod": false,
229 "Users.AdminNotifierEmailFrom": false,
230 "Users.AnonymousUserToken": true,
231 "Users.AutoAdminFirstUser": false,
232 "Users.AutoAdminUserWithEmail": false,
233 "Users.AutoSetupNewUsers": false,
234 "Users.AutoSetupNewUsersWithVmUUID": false,
235 "Users.AutoSetupUsernameBlacklist": false,
236 "Users.CanCreateRoleGroups": true,
237 "Users.EmailSubjectPrefix": false,
238 "Users.NewInactiveUserNotificationRecipients": false,
239 "Users.NewUserNotificationRecipients": false,
240 "Users.NewUsersAreActive": false,
241 "Users.PreferDomainForUsername": false,
242 "Users.RoleGroupsVisibleToAll": false,
243 "Users.SendUserSetupNotificationEmail": false,
244 "Users.SupportEmailAddress": true,
245 "Users.SyncIgnoredGroups": true,
246 "Users.SyncRequiredGroups": true,
247 "Users.SyncUserAccounts": true,
248 "Users.SyncUserAPITokens": true,
249 "Users.SyncUserGroups": true,
250 "Users.SyncUserSSHKeys": true,
251 "Users.UserNotifierEmailBcc": false,
252 "Users.UserNotifierEmailFrom": false,
253 "Users.UserProfileNotificationAddress": false,
254 "Users.UserSetupMailText": false,
257 "Volumes.*.*": false,
258 "Volumes.*.AccessViaHosts": true,
259 "Volumes.*.AccessViaHosts.*": true,
260 "Volumes.*.AccessViaHosts.*.ReadOnly": true,
261 "Volumes.*.ReadOnly": true,
262 "Volumes.*.Replication": true,
263 "Volumes.*.StorageClasses": true,
264 "Volumes.*.StorageClasses.*": true,
266 "Workbench.ActivationContactLink": false,
267 "Workbench.APIClientConnectTimeout": true,
268 "Workbench.APIClientReceiveTimeout": true,
269 "Workbench.APIResponseCompression": true,
270 "Workbench.ApplicationMimetypesWithViewIcon": true,
271 "Workbench.ApplicationMimetypesWithViewIcon.*": true,
272 "Workbench.ArvadosDocsite": true,
273 "Workbench.ArvadosPublicDataDocURL": true,
274 "Workbench.BannerUUID": true,
275 "Workbench.DefaultOpenIdPrefix": false,
276 "Workbench.DisableSharingURLsUI": true,
277 "Workbench.EnableGettingStartedPopup": true,
278 "Workbench.EnablePublicProjectsPage": true,
279 "Workbench.FileViewersConfigURL": true,
280 "Workbench.IdleTimeout": true,
281 "Workbench.InactivePageHTML": true,
282 "Workbench.LogViewerMaxBytes": true,
283 "Workbench.MultiSiteSearch": true,
284 "Workbench.ProfilingEnabled": true,
285 "Workbench.Repositories": false,
286 "Workbench.RepositoryCache": false,
287 "Workbench.RunningJobLogRecordsToFetch": true,
288 "Workbench.ShowRecentCollectionsOnDashboard": true,
289 "Workbench.ShowUserAgreementInline": true,
290 "Workbench.ShowUserNotifications": true,
291 "Workbench.SiteName": true,
292 "Workbench.SSHHelpHostSuffix": true,
293 "Workbench.SSHHelpPageHTML": true,
294 "Workbench.Theme": true,
295 "Workbench.UserProfileFormFields": true,
296 "Workbench.UserProfileFormFields.*": true,
297 "Workbench.UserProfileFormFields.*.*": true,
298 "Workbench.UserProfileFormFields.*.*.*": true,
299 "Workbench.UserProfileFormMessage": true,
300 "Workbench.WelcomePageHTML": true,
303 func redactUnsafe(m map[string]interface{}, mPrefix, lookupPrefix string) error {
305 for k, v := range m {
307 safe, ok := whitelist[lookupPrefix+k]
310 safe, ok = whitelist[lookupPrefix+"*"]
313 errs = append(errs, fmt.Sprintf("config bug: key %q not in whitelist map", lookupPrefix+k))
320 if v, ok := v.(map[string]interface{}); ok {
321 err := redactUnsafe(v, mPrefix+k+".", lookupPrefix+lookupKey+".")
323 errs = append(errs, err.Error())
328 return errors.New(strings.Join(errs, "\n"))