14715: Adds keepproxy to cluster config loading
[arvados.git] / lib / config / export.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "encoding/json"
9         "errors"
10         "fmt"
11         "io"
12         "strings"
13
14         "git.curoverse.com/arvados.git/sdk/go/arvados"
15 )
16
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)
21         if err != nil {
22                 return err
23         }
24         var m map[string]interface{}
25         err = json.Unmarshal(buf, &m)
26         if err != nil {
27                 return err
28         }
29
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, "", "")
34         if err != nil {
35                 return err
36         }
37         return json.NewEncoder(w).Encode(m)
38 }
39
40 // whitelist classifies configs as safe/unsafe to reveal to
41 // unauthenticated clients.
42 //
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.
49 //
50 // Example: API.RequestTimeout is safe because whitelist["API"] == and
51 // whitelist["API.RequestTimeout"] == true.
52 //
53 // Example: PostgreSQL.Connection.password is not safe because
54 // whitelist["PostgreSQL.Connection"] == false.
55 //
56 // Example: PostgreSQL.BadKey would cause an error because
57 // whitelist["PostgreSQL"] isn't false, and neither
58 // whitelist["PostgreSQL.BadKey"] nor whitelist["PostgreSQL.*"]
59 // exists.
60 var whitelist = map[string]bool{
61         // | sort -t'"' -k2,2
62         "ClusterID":                                    true,
63         "API":                                          true,
64         "API.AsyncPermissionsUpdateInterval":           false,
65         "API.DisabledAPIs":                             false,
66         "API.MaxIndexDatabaseRead":                     false,
67         "API.MaxItemsPerResponse":                      true,
68         "API.MaxRequestAmplification":                  false,
69         "API.MaxRequestSize":                           true,
70         "API.RailsSessionSecretToken":                  false,
71         "API.RequestTimeout":                           true,
72         "API.WebsocketClientEventQueue":                false,
73         "API.SendTimeout":                              true,
74         "API.WebsocketServerEventQueue":                false,
75         "API.KeepServiceRequestTimeout":                false,
76         "AuditLogs":                                    false,
77         "AuditLogs.MaxAge":                             false,
78         "AuditLogs.MaxDeleteBatch":                     false,
79         "AuditLogs.UnloggedAttributes":                 false,
80         "Collections":                                  true,
81         "Collections.BlobSigning":                      true,
82         "Collections.BlobSigningKey":                   false,
83         "Collections.BlobSigningTTL":                   true,
84         "Collections.CollectionVersioning":             false,
85         "Collections.DefaultReplication":               true,
86         "Collections.DefaultTrashLifetime":             true,
87         "Collections.ManagedProperties":                true,
88         "Collections.ManagedProperties.*":              true,
89         "Collections.ManagedProperties.*.*":            true,
90         "Collections.PreserveVersionIfIdle":            true,
91         "Collections.TrashSweepInterval":               false,
92         "Collections.TrustAllContent":                  false,
93         "Containers":                                   true,
94         "Containers.CloudVMs":                          false,
95         "Containers.CrunchRunCommand":                  false,
96         "Containers.CrunchRunArgumentsList":            false,
97         "Containers.DefaultKeepCacheRAM":               true,
98         "Containers.DispatchPrivateKey":                false,
99         "Containers.JobsAPI":                           true,
100         "Containers.JobsAPI.CrunchJobUser":             false,
101         "Containers.JobsAPI.CrunchJobWrapper":          false,
102         "Containers.JobsAPI.CrunchRefreshTrigger":      false,
103         "Containers.JobsAPI.DefaultDockerImage":        false,
104         "Containers.JobsAPI.Enable":                    true,
105         "Containers.JobsAPI.GitInternalDir":            false,
106         "Containers.JobsAPI.ReuseJobIfOutputsDiffer":   false,
107         "Containers.Logging":                           false,
108         "Containers.LogReuseDecisions":                 false,
109         "Containers.MaxComputeVMs":                     false,
110         "Containers.MaxDispatchAttempts":               false,
111         "Containers.MaxRetryAttempts":                  true,
112         "Containers.MinRetryPeriod":                    true,
113         "Containers.ReserveExtraRAM":                   true,
114         "Containers.SLURM":                             false,
115         "Containers.StaleLockTimeout":                  false,
116         "Containers.SupportedDockerImageFormats":       true,
117         "Containers.SupportedDockerImageFormats.*":     true,
118         "Containers.UsePreemptibleInstances":           true,
119         "EnableBetaController14287":                    false,
120         "Git":                                          false,
121         "InstanceTypes":                                true,
122         "InstanceTypes.*":                              true,
123         "InstanceTypes.*.*":                            true,
124         "Login":                                        false,
125         "Mail":                                         false,
126         "ManagementToken":                              false,
127         "PostgreSQL":                                   false,
128         "RemoteClusters":                               true,
129         "RemoteClusters.*":                             true,
130         "RemoteClusters.*.ActivateUsers":               true,
131         "RemoteClusters.*.Host":                        true,
132         "RemoteClusters.*.Insecure":                    true,
133         "RemoteClusters.*.Proxy":                       true,
134         "RemoteClusters.*.Scheme":                      true,
135         "Services":                                     true,
136         "Services.*":                                   true,
137         "Services.*.ExternalURL":                       true,
138         "Services.*.InternalURLs":                      false,
139         "SystemLogs":                                   false,
140         "SystemRootToken":                              false,
141         "TLS":                                          false,
142         "Users":                                        true,
143         "Users.AnonymousUserToken":                     true,
144         "Users.AdminNotifierEmailFrom":                 false,
145         "Users.AutoAdminFirstUser":                     false,
146         "Users.AutoAdminUserWithEmail":                 false,
147         "Users.AutoSetupNewUsers":                      false,
148         "Users.AutoSetupNewUsersWithRepository":        false,
149         "Users.AutoSetupNewUsersWithVmUUID":            false,
150         "Users.AutoSetupUsernameBlacklist":             false,
151         "Users.EmailSubjectPrefix":                     false,
152         "Users.NewInactiveUserNotificationRecipients":  false,
153         "Users.NewUserNotificationRecipients":          false,
154         "Users.NewUsersAreActive":                      false,
155         "Users.UserNotifierEmailFrom":                  false,
156         "Users.UserProfileNotificationAddress":         false,
157         "Workbench":                                    true,
158         "Workbench.ActivationContactLink":              false,
159         "Workbench.APIClientConnectTimeout":            true,
160         "Workbench.APIClientReceiveTimeout":            true,
161         "Workbench.APIResponseCompression":             true,
162         "Workbench.ApplicationMimetypesWithViewIcon":   true,
163         "Workbench.ApplicationMimetypesWithViewIcon.*": true,
164         "Workbench.ArvadosDocsite":                     true,
165         "Workbench.ArvadosPublicDataDocURL":            true,
166         "Workbench.DefaultOpenIdPrefix":                false,
167         "Workbench.EnableGettingStartedPopup":          true,
168         "Workbench.EnablePublicProjectsPage":           true,
169         "Workbench.FileViewersConfigURL":               true,
170         "Workbench.LogViewerMaxBytes":                  true,
171         "Workbench.MultiSiteSearch":                    true,
172         "Workbench.ProfilingEnabled":                   true,
173         "Workbench.Repositories":                       false,
174         "Workbench.RepositoryCache":                    false,
175         "Workbench.RunningJobLogRecordsToFetch":        true,
176         "Workbench.SecretKeyBase":                      false,
177         "Workbench.ShowRecentCollectionsOnDashboard":   true,
178         "Workbench.ShowUserAgreementInline":            true,
179         "Workbench.ShowUserNotifications":              true,
180         "Workbench.SiteName":                           true,
181         "Workbench.Theme":                              true,
182         "Workbench.UserProfileFormFields":              true,
183         "Workbench.UserProfileFormFields.*":            true,
184         "Workbench.UserProfileFormFields.*.*":          true,
185         "Workbench.UserProfileFormFields.*.*.*":        true,
186         "Workbench.UserProfileFormMessage":             true,
187         "Workbench.VocabularyURL":                      true,
188 }
189
190 func redactUnsafe(m map[string]interface{}, mPrefix, lookupPrefix string) error {
191         var errs []string
192         for k, v := range m {
193                 lookupKey := k
194                 safe, ok := whitelist[lookupPrefix+k]
195                 if !ok {
196                         lookupKey = "*"
197                         safe, ok = whitelist[lookupPrefix+"*"]
198                 }
199                 if !ok {
200                         errs = append(errs, fmt.Sprintf("config bug: key %q not in whitelist map", lookupPrefix+k))
201                         continue
202                 }
203                 if !safe {
204                         delete(m, k)
205                         continue
206                 }
207                 if v, ok := v.(map[string]interface{}); ok {
208                         err := redactUnsafe(v, mPrefix+k+".", lookupPrefix+lookupKey+".")
209                         if err != nil {
210                                 errs = append(errs, err.Error())
211                         }
212                 }
213         }
214         if len(errs) > 0 {
215                 return errors.New(strings.Join(errs, "\n"))
216         }
217         return nil
218 }