Skip to content

Commit 299c863

Browse files
authored
Merge pull request #1448 from nono/docker-disable-csp
Allow to disable CSP from config file (dev only)
2 parents 6cab7bc + 72f36d3 commit 299c863

File tree

11 files changed

+51
-68
lines changed

11 files changed

+51
-68
lines changed

cmd/apps.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var installWebappCmd = &cobra.Command{
5454
Use: "install [slug] [sourceurl]",
5555
Short: `Install an application with the specified slug name
5656
from the given source URL.`,
57-
Example: "$ cozy-stack apps install --domain cozy.tools:8080 drive 'git://github.com/cozy/cozy-drive.git#latest-drive'",
57+
Example: "$ cozy-stack apps install --domain cozy.tools:8080 drive registry://drive/stable",
5858
Long: "[Some schemes](../../docs/apps.md#sources) are allowed as `[sourceurl]`.",
5959
RunE: func(cmd *cobra.Command, args []string) error {
6060
return installApp(cmd, args, consts.Apps)
@@ -129,7 +129,7 @@ var installKonnectorCmd = &cobra.Command{
129129
Use: "install [slug] [sourceurl]",
130130
Short: `Install a konnector with the specified slug name
131131
from the given source URL.`,
132-
Example: "$ cozy-stack konnectors install --domain cozy.tools:8080 trainline 'git://github.com/cozy/cozy-konnector-trainline.git#build'",
132+
Example: "$ cozy-stack konnectors install --domain cozy.tools:8080 trainline registry://trainline/stable",
133133
RunE: func(cmd *cobra.Command, args []string) error {
134134
return installApp(cmd, args, consts.Konnectors)
135135
},
@@ -252,14 +252,8 @@ func installApp(cmd *cobra.Command, args []string, appType string) error {
252252
return cmd.Usage()
253253
}
254254
slug := args[0]
255-
var source string
256-
if len(args) == 1 {
257-
s, ok := consts.AppsRegistry[slug]
258-
if !ok {
259-
return cmd.Usage()
260-
}
261-
source = s
262-
} else {
255+
source := "registry://" + slug + "/stable"
256+
if len(args) > 1 {
263257
source = args[1]
264258
}
265259
if flagAllDomains {

cmd/serve.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
var flagAllowRoot bool
2424
var flagAppdirs []string
25-
var flagDisableCSP bool
2625
var flagDevMode bool
2726

2827
// serveCmd represents the serve command
@@ -59,13 +58,6 @@ example), you can use the --appdir flag like this:
5958
config.BuildMode = config.ModeDev
6059
}
6160

62-
if flagDisableCSP {
63-
if !config.IsDevRelease() {
64-
return errors.New("Using --disable-csp is allowed only for development")
65-
}
66-
config.GetConfig().CSPDisabled = true
67-
}
68-
6961
var apps map[string]string
7062
if len(flagAppdirs) > 0 {
7163
apps = make(map[string]string)
@@ -218,7 +210,8 @@ func init() {
218210
flags.BoolVar(&flagAllowRoot, "allow-root", false, "Allow to start as root (disabled by default)")
219211
flags.StringSliceVar(&flagAppdirs, "appdir", nil, "Mount a directory as the 'app' application")
220212

221-
flags.BoolVar(&flagDisableCSP, "disable-csp", false, "Disable the Content Security Policy (only available for development)")
213+
flags.Bool("disable-csp", false, "Disable the Content Security Policy (only available for development)")
214+
checkNoErr(viper.BindPFlag("disable_csp", flags.Lookup("disable-csp")))
222215

223216
flags.String("csp-whitelist", "", "Whitelisted domains for the default allowed origins of the Content Secury Policy")
224217
checkNoErr(viper.BindPFlag("csp_whitelist", flags.Lookup("csp-whitelist")))

cozy.example.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ csp_whitelist:
224224
# style: https://whitelisted.domain.com/
225225
# font: https://whitelisted.domain.com/
226226

227+
# It can useful to disable the CSP policy to debug and test things in local
228+
# disable_csp: true
229+
227230
log:
228231
# logger level (debug, info, warning, panic, fatal) - flags: --log-level
229232
level: info

docs/cli/cozy-stack_apps_install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cozy-stack apps install [slug] [sourceurl] [flags]
1414
### Examples
1515

1616
```
17-
$ cozy-stack apps install --domain cozy.tools:8080 drive 'git://github.com/cozy/cozy-drive.git#latest-drive'
17+
$ cozy-stack apps install --domain cozy.tools:8080 drive registry://drive/stable
1818
```
1919

2020
### Options

docs/cli/cozy-stack_instances_add.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ $ cozy-stack instances add --dev --passphrase cozy --apps drive,photos,settings
2626
### Options
2727

2828
```
29-
--apps strings Apps to be preinstalled
30-
--context-name string Context name of the instance
31-
--dev To create a development instance
32-
--disk-quota string The quota allowed to the instance's VFS
33-
--email string The email of the owner
34-
-h, --help help for add
35-
--locale string Locale of the new cozy instance (default "en")
36-
--passphrase string Register the instance with this passphrase (useful for tests)
37-
--public-name string The public name of the owner
38-
--settings string A list of settings (eg context:foo,offer:premium)
39-
--swift-cluster int Specify a cluster number for swift
40-
--tos string The TOS version signed
41-
--tz string The timezone for the user
42-
--uuid string The UUID of the instance
29+
--apps strings Apps to be preinstalled
30+
--context-name string Context name of the instance
31+
--dev To create a development instance
32+
--disk-quota string The quota allowed to the instance's VFS
33+
--domain-aliases strings Specify one or more aliases domain for the instance (separated by ',')
34+
--email string The email of the owner
35+
-h, --help help for add
36+
--locale string Locale of the new cozy instance (default "en")
37+
--passphrase string Register the instance with this passphrase (useful for tests)
38+
--public-name string The public name of the owner
39+
--settings string A list of settings (eg context:foo,offer:premium)
40+
--swift-cluster int Specify a cluster number for swift
41+
--tos string The TOS version signed
42+
--tz string The timezone for the user
43+
--uuid string The UUID of the instance
4344
```
4445

4546
### Options inherited from parent commands

docs/cli/cozy-stack_instances_modify.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ cozy-stack instances modify [domain] [flags]
1616
### Options
1717

1818
```
19-
--context-name string New context name
20-
--disk-quota string Specify a new disk quota
21-
--email string New email
22-
-h, --help help for modify
23-
--locale string New locale (default "en")
24-
--onboarding-finished Force the finishing of the onboarding
25-
--public-name string New public name
26-
--settings string New list of settings (eg offer:premium)
27-
--swift-cluster int New swift cluster
28-
--tos string Update the TOS version signed
29-
--tos-latest string Update the latest TOS version
30-
--tz string New timezone
31-
--uuid string New UUID
19+
--context-name string New context name
20+
--disk-quota string Specify a new disk quota
21+
--domain-aliases strings Specify one or more aliases domain for the instance (separated by ',')
22+
--email string New email
23+
-h, --help help for modify
24+
--locale string New locale (default "en")
25+
--onboarding-finished Force the finishing of the onboarding
26+
--public-name string New public name
27+
--settings string New list of settings (eg offer:premium)
28+
--swift-cluster int New swift cluster
29+
--tos string Update the TOS version signed
30+
--tos-latest string Update the latest TOS version
31+
--tz string New timezone
32+
--uuid string New UUID
3233
```
3334

3435
### Options inherited from parent commands

docs/cli/cozy-stack_instances_update.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ cozy-stack instances update [slugs...] [flags]
1616
### Options
1717

1818
```
19-
--all-domains Work on all domains iterativelly
20-
--domain string Specify the domain name of the instance
21-
--force-registry Force to update all applications sources from git to the registry
22-
-h, --help help for update
19+
--all-domains Work on all domains iterativelly
20+
--context-name string Work only on the instances with the given context name
21+
--domain string Specify the domain name of the instance
22+
--force-registry Force to update all applications sources from git to the registry
23+
-h, --help help for update
24+
--only-registry Only update applications installed from the registry
2325
```
2426

2527
### Options inherited from parent commands

docs/cli/cozy-stack_konnectors_install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cozy-stack konnectors install [slug] [sourceurl] [flags]
1515
### Examples
1616

1717
```
18-
$ cozy-stack konnectors install --domain cozy.tools:8080 trainline 'git://github.com/cozy/cozy-konnector-trainline.git#build'
18+
$ cozy-stack konnectors install --domain cozy.tools:8080 trainline registry://trainline/stable
1919
```
2020

2121
### Options

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ func UseViper(v *viper.Viper) error {
629629
CSPWhitelist: v.GetStringMapString("csp_whitelist"),
630630
}
631631

632+
if IsDevRelease() && v.GetBool("disable_csp") {
633+
config.CSPDisabled = true
634+
}
635+
632636
return logger.Init(config.Logger)
633637
}
634638

pkg/consts/consts.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,3 @@ const (
109109
// InstanceSettingsID is the id of settings document for the instance
110110
InstanceSettingsID = "io.cozy.settings.instance"
111111
)
112-
113-
// AppsRegistry is an hard-coded list of known apps, with their source URLs
114-
// TODO remove it when we will have a true registry
115-
var AppsRegistry = map[string]string{
116-
"onboarding": "git://github.com/cozy/cozy-onboarding-v3.git#latest",
117-
"drive": "git://github.com/cozy/cozy-drive.git#latest-drive",
118-
"photos": "git://github.com/cozy/cozy-drive.git#latest-photos",
119-
"settings": "git://github.com/cozy/cozy-settings.git#latest",
120-
"collect": "git://github.com/cozy/cozy-collect.git#latest",
121-
"banks": "git://github.com/cozy/cozy-banks.git#latest",
122-
"contacts": "git://github.com/cozy/cozy-contacts.git#latest",
123-
}

0 commit comments

Comments
 (0)