Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user config dir to store tls artifacts #2129

Merged
merged 26 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/tls-artefacts-out-of-binary-location.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Use system default location to store TLS artefacts

This used to default to the current location of the binary, which is not ideal after a first run as it leaves traces behind. It now uses the system's location for artefacts with the help of https://golang.org/pkg/os/#UserConfigDir.

https://github.com/owncloud/ocis/pull/2129
4 changes: 2 additions & 2 deletions glauth/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"github.com/oklog/run"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/glauth/pkg/config"
"github.com/owncloud/ocis/glauth/pkg/crypto"
"github.com/owncloud/ocis/glauth/pkg/flagset"
"github.com/owncloud/ocis/glauth/pkg/metrics"
"github.com/owncloud/ocis/glauth/pkg/server/debug"
"github.com/owncloud/ocis/glauth/pkg/server/glauth"
"github.com/owncloud/ocis/glauth/pkg/tracing"
pkgcrypto "github.com/owncloud/ocis/ocis-pkg/crypto"
"github.com/owncloud/ocis/ocis-pkg/service/grpc"
"github.com/owncloud/ocis/ocis-pkg/sync"
)
Expand Down Expand Up @@ -100,7 +100,7 @@ func Server(cfg *config.Config) *cli.Command {
}

if lscfg.Enabled {
if err := crypto.GenCert(cfg.Ldaps.Cert, cfg.Ldaps.Key, logger); err != nil {
if err := pkgcrypto.GenCert(cfg.Ldaps.Cert, cfg.Ldaps.Key, logger); err != nil {
refs marked this conversation as resolved.
Show resolved Hide resolved
logger.Fatal().Err(err).Msgf("Could not generate test-certificate")
}
}
Expand Down
148 changes: 0 additions & 148 deletions glauth/pkg/crypto/gencert.go

This file was deleted.

15 changes: 13 additions & 2 deletions glauth/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package flagset

import (
"os"
"path"

"github.com/micro/cli/v2"
"github.com/owncloud/ocis/glauth/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/flags"
Expand Down Expand Up @@ -43,6 +46,14 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag {
}
}

func mustUserConfigDir() string {
dir, err := os.UserConfigDir()
if err != nil {
panic(err)
}
return path.Join(dir, "ldap")
}

// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
Expand Down Expand Up @@ -158,14 +169,14 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "ldaps-cert",
Value: flags.OverrideDefaultString(cfg.Ldaps.Cert, "./ldap.crt"),
Value: flags.OverrideDefaultString(cfg.Ldaps.Cert, path.Join(mustUserConfigDir(), "ldap.crt")),
Usage: "path to ldaps certificate in PEM format",
EnvVars: []string{"GLAUTH_LDAPS_CERT"},
Destination: &cfg.Ldaps.Cert,
},
&cli.StringFlag{
Name: "ldaps-key",
Value: flags.OverrideDefaultString(cfg.Ldaps.Key, "./ldap.key"),
Value: flags.OverrideDefaultString(cfg.Ldaps.Key, path.Join(mustUserConfigDir(), "ldap.key")),
Usage: "path to ldaps key in PEM format",
EnvVars: []string{"GLAUTH_LDAPS_KEY"},
Destination: &cfg.Ldaps.Key,
Expand Down
123 changes: 0 additions & 123 deletions idp/pkg/crypto/gencert.go

This file was deleted.

15 changes: 13 additions & 2 deletions idp/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package flagset

import (
"os"
"path"

"github.com/micro/cli/v2"
"github.com/owncloud/ocis/idp/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/flags"
Expand Down Expand Up @@ -43,6 +46,14 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag {
}
}

func mustUserConfigDir() string {
dir, err := os.UserConfigDir()
if err != nil {
panic(err)
}
return path.Join(dir, "idp")
}

// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
Expand Down Expand Up @@ -233,14 +244,14 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "transport-tls-cert",
Value: flags.OverrideDefaultString(cfg.HTTP.TLSCert, ""),
Value: flags.OverrideDefaultString(cfg.HTTP.TLSCert, path.Join(mustUserConfigDir(), "server.crt")),
Usage: "Certificate file for transport encryption",
EnvVars: []string{"IDP_TRANSPORT_TLS_CERT"},
Destination: &cfg.HTTP.TLSCert,
},
&cli.StringFlag{
Name: "transport-tls-key",
Value: flags.OverrideDefaultString(cfg.HTTP.TLSKey, ""),
Value: flags.OverrideDefaultString(cfg.HTTP.TLSKey, path.Join(mustUserConfigDir(), "server.key")),
Usage: "Secret file for transport encryption",
EnvVars: []string{"IDP_TRANSPORT_TLS_KEY"},
Destination: &cfg.HTTP.TLSKey,
Expand Down
Loading