1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/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)
29 err = redactUnsafe(m, "", "")
33 return json.NewEncoder(w).Encode(m)
36 // whitelist classifies configs as safe/unsafe to reveal to
37 // unauthenticated clients.
39 // Every config entry must either be listed explicitly here along with
40 // all of its parent keys (e.g., "API" + "API.RequestTimeout"), or
41 // have an ancestor listed as false (e.g.,
42 // "PostgreSQL.Connection.password" has an ancestor
43 // "PostgreSQL.Connection" with a false value). Otherwise, it is a bug
44 // which should be caught by tests.
46 // Example: API.RequestTimeout is safe because whitelist["API"] == and
47 // whitelist["API.RequestTimeout"] == true.
49 // Example: PostgreSQL.Connection.password is not safe because
50 // whitelist["PostgreSQL.Connection"] == false.
52 // Example: PostgreSQL.BadKey would cause an error because
53 // whitelist["PostgreSQL"] isn't false, and neither
54 // whitelist["PostgreSQL.BadKey"] nor whitelist["PostgreSQL.*"]
56 var whitelist = map[string]bool{
59 "API.AsyncPermissionsUpdateInterval": false,
60 "API.DisabledAPIs": false,
61 "API.MaxIndexDatabaseRead": false,
62 "API.MaxItemsPerResponse": true,
63 "API.MaxRequestAmplification": false,
64 "API.MaxRequestSize": true,
65 "API.RailsSessionSecretToken": false,
66 "API.RequestTimeout": true,
67 "API.WebsocketClientEventQueue": false,
68 "API.SendTimeout": true,
69 "API.WebsocketServerEventQueue": false,
71 "AuditLogs.MaxAge": false,
72 "AuditLogs.MaxDeleteBatch": false,
73 "AuditLogs.UnloggedAttributes": false,
75 "Collections.BlobSigning": true,
76 "Collections.BlobSigningKey": false,
77 "Collections.BlobSigningTTL": true,
78 "Collections.CollectionVersioning": false,
79 "Collections.DefaultReplication": true,
80 "Collections.DefaultTrashLifetime": true,
81 "Collections.ManagedProperties": true,
82 "Collections.ManagedProperties.*": true,
83 "Collections.ManagedProperties.*.*": true,
84 "Collections.PreserveVersionIfIdle": true,
85 "Collections.TrashSweepInterval": false,
86 "Collections.TrustAllContent": false,
88 "Containers.CloudVMs": false,
89 "Containers.CrunchRunCommand": false,
90 "Containers.CrunchRunArgumentsList": false,
91 "Containers.DefaultKeepCacheRAM": true,
92 "Containers.DispatchPrivateKey": false,
93 "Containers.JobsAPI": true,
94 "Containers.JobsAPI.CrunchJobUser": false,
95 "Containers.JobsAPI.CrunchJobWrapper": false,
96 "Containers.JobsAPI.CrunchRefreshTrigger": false,
97 "Containers.JobsAPI.DefaultDockerImage": false,
98 "Containers.JobsAPI.Enable": true,
99 "Containers.JobsAPI.GitInternalDir": false,
100 "Containers.JobsAPI.ReuseJobIfOutputsDiffer": false,
101 "Containers.Logging": false,
102 "Containers.LogReuseDecisions": false,
103 "Containers.MaxComputeVMs": false,
104 "Containers.MaxDispatchAttempts": false,
105 "Containers.MaxRetryAttempts": true,
106 "Containers.MinRetryPeriod": true,
107 "Containers.ReserveExtraRAM": true,
108 "Containers.SLURM": false,
109 "Containers.StaleLockTimeout": false,
110 "Containers.SupportedDockerImageFormats": true,
111 "Containers.SupportedDockerImageFormats.*": true,
112 "Containers.UsePreemptibleInstances": true,
113 "EnableBetaController14287": false,
115 "InstanceTypes": true,
116 "InstanceTypes.*": true,
117 "InstanceTypes.*.*": true,
120 "ManagementToken": false,
122 "RemoteClusters": true,
123 "RemoteClusters.*": true,
124 "RemoteClusters.*.ActivateUsers": true,
125 "RemoteClusters.*.Host": true,
126 "RemoteClusters.*.Insecure": true,
127 "RemoteClusters.*.Proxy": true,
128 "RemoteClusters.*.Scheme": true,
131 "Services.*.ExternalURL": true,
132 "Services.*.InternalURLs": false,
134 "SystemRootToken": false,
137 "Users.AnonymousUserToken": true,
138 "Users.AdminNotifierEmailFrom": false,
139 "Users.AutoAdminFirstUser": false,
140 "Users.AutoAdminUserWithEmail": false,
141 "Users.AutoSetupNewUsers": false,
142 "Users.AutoSetupNewUsersWithRepository": false,
143 "Users.AutoSetupNewUsersWithVmUUID": false,
144 "Users.AutoSetupUsernameBlacklist": false,
145 "Users.EmailSubjectPrefix": false,
146 "Users.NewInactiveUserNotificationRecipients": false,
147 "Users.NewUserNotificationRecipients": false,
148 "Users.NewUsersAreActive": false,
149 "Users.UserNotifierEmailFrom": false,
150 "Users.UserProfileNotificationAddress": false,
152 "Workbench.ActivationContactLink": false,
153 "Workbench.APIClientConnectTimeout": true,
154 "Workbench.APIClientReceiveTimeout": true,
155 "Workbench.APIResponseCompression": true,
156 "Workbench.ApplicationMimetypesWithViewIcon": true,
157 "Workbench.ApplicationMimetypesWithViewIcon.*": true,
158 "Workbench.ArvadosDocsite": true,
159 "Workbench.ArvadosPublicDataDocURL": true,
160 "Workbench.DefaultOpenIdPrefix": false,
161 "Workbench.EnableGettingStartedPopup": true,
162 "Workbench.EnablePublicProjectsPage": true,
163 "Workbench.FileViewersConfigURL": true,
164 "Workbench.LogViewerMaxBytes": true,
165 "Workbench.MultiSiteSearch": true,
166 "Workbench.ProfilingEnabled": true,
167 "Workbench.Repositories": false,
168 "Workbench.RepositoryCache": false,
169 "Workbench.RunningJobLogRecordsToFetch": true,
170 "Workbench.SecretKeyBase": false,
171 "Workbench.ShowRecentCollectionsOnDashboard": true,
172 "Workbench.ShowUserAgreementInline": true,
173 "Workbench.ShowUserNotifications": true,
174 "Workbench.SiteName": true,
175 "Workbench.Theme": true,
176 "Workbench.UserProfileFormFields": true,
177 "Workbench.UserProfileFormFields.*": true,
178 "Workbench.UserProfileFormFields.*.*": true,
179 "Workbench.UserProfileFormFields.*.*.*": true,
180 "Workbench.UserProfileFormMessage": true,
181 "Workbench.VocabularyURL": true,
184 func redactUnsafe(m map[string]interface{}, mPrefix, lookupPrefix string) error {
186 for k, v := range m {
188 safe, ok := whitelist[lookupPrefix+k]
191 safe, ok = whitelist[lookupPrefix+"*"]
194 errs = append(errs, fmt.Sprintf("config bug: key %q not in whitelist map", lookupPrefix+k))
201 if v, ok := v.(map[string]interface{}); ok {
202 err := redactUnsafe(v, mPrefix+k+".", lookupPrefix+lookupKey+".")
204 errs = append(errs, err.Error())
209 return errors.New(strings.Join(errs, "\n"))