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

Add SSL configuration for RGW #355

Merged
merged 41 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e84775b
Add SSL configuration for RGW
marceloneppel May 31, 2024
2aee678
Update documentation
marceloneppel Jun 3, 2024
ac27b53
Use explicit SSL related variables in the template
marceloneppel Jun 4, 2024
faa2370
Test
marceloneppel Jun 7, 2024
108fe62
Test
marceloneppel Jun 7, 2024
4c2490c
Test
marceloneppel Jun 7, 2024
1e1448a
Test
marceloneppel Jun 7, 2024
618a1da
Test
marceloneppel Jun 7, 2024
8dcf73f
Merge remote-tracking branch 'upstream/main' into rgw-https-support-t…
marceloneppel Jun 18, 2024
c5ac16f
Merge remote-tracking branch 'upstream/main' into rgw-https-support-t…
marceloneppel Jun 18, 2024
424c643
Improve
marceloneppel Jul 1, 2024
543e569
Improve
marceloneppel Jul 1, 2024
437efdb
Improve
marceloneppel Jul 1, 2024
f6f52dd
Improve
marceloneppel Jul 1, 2024
b9de35c
Improve
marceloneppel Jul 1, 2024
f7ef8de
Improve
marceloneppel Jul 1, 2024
ee794c1
Improve
marceloneppel Jul 1, 2024
13b80c0
Improve
marceloneppel Jul 1, 2024
7c0841f
Improve
marceloneppel Jul 1, 2024
d4cce8d
Improve
marceloneppel Jul 1, 2024
9bbf550
Improve
marceloneppel Jul 1, 2024
6e02986
Improve
marceloneppel Jul 1, 2024
d73b2bf
Fix library
marceloneppel Jul 1, 2024
83cb844
Fix library
marceloneppel Jul 1, 2024
d46ba7b
Improve
marceloneppel Jul 1, 2024
cd161dd
Improve
marceloneppel Jul 1, 2024
d098cc8
Test
marceloneppel Aug 16, 2024
926f18d
Test
marceloneppel Aug 16, 2024
f8ea05c
Test
marceloneppel Aug 16, 2024
d3d2434
Test
marceloneppel Aug 16, 2024
97327b5
Merge remote-tracking branch 'upstream/main' into rgw-https-support-t…
marceloneppel Aug 16, 2024
760acfc
Fix docs
marceloneppel Aug 16, 2024
bcd0777
Remove install hook code
marceloneppel Aug 16, 2024
6cd45ee
Fix docs
marceloneppel Aug 16, 2024
6fc6055
Fix CLI
marceloneppel Aug 16, 2024
97a4f4f
Fix unit tests
marceloneppel Aug 16, 2024
2f57281
Merge pull request #2 from marceloneppel/rgw-https-support-test-1
marceloneppel Aug 16, 2024
3e794a4
Fix SSL files deletion
marceloneppel Aug 16, 2024
5f60871
Add functional test
marceloneppel Aug 16, 2024
3035631
Fix SSL files permissions
marceloneppel Aug 19, 2024
80f4440
Use std lib os.WriteFile()
marceloneppel Aug 19, 2024
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
9 changes: 9 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ jobs:
- name: Exercise RGW
run: ~/actionutils.sh testrgw

- name: Disable RGW
run: ~/actionutils.sh disable_rgw

- name: Enable RGW with SSL enabled
run: ~/actionutils.sh enable_rgw_ssl

- name: Exercise RGW with SSL enabled
run: ~/actionutils.sh testrgw_ssl

- name: Test Cluster Config
run: |
set -eux
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.snap
_build
*.swp
.idea
.vscode
11 changes: 7 additions & 4 deletions docs/reference/commands/enable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ Usage:

.. code-block:: none

microceph enable rgw [--port <port>] [--target <server>] [--wait <bool>] [flags]
microceph enable rgw [--port <port>] [--ssl-port <port>] [--ssl-certificate <certificate material>] [--ssl-private-key <private key material>] [--target <server>] [--wait <bool>] [flags]


Flags:

.. code-block:: none

--port int Service port (default: 80) (default 80)
--target string Server hostname (default: this server)
--wait Wait for rgw service to be up. (default true)
--port int Service non-SSL port (default: 80) (default 80)
--ssl-port int Service SSL port (default: 443) (default 443)
--ssl-certificate string base64 encoded SSL certificate
--ssl-private-key string base64 encoded SSL private key
--target string Server hostname (default: this server)
--wait Wait for rgw service to be up. (default true)
2 changes: 1 addition & 1 deletion microceph/ceph/configwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ auth allow insecure global id reclaim = false

[client.radosgw.gateway]
rgw init timeout = 1200
rgw frontends = beast port={{.rgwPort}}
rgw frontends = beast{{if or (ne .rgwPort 0) (not .sslCertificatePath) (not .sslPrivateKeyPath)}} port={{.rgwPort}}{{end}}{{if and .sslCertificatePath .sslPrivateKeyPath}} ssl_port={{.sslPort}} ssl_certificate={{.sslCertificatePath}} ssl_private_key={{.sslPrivateKeyPath}}{{end}}
`)),
configFile: "radosgw.conf",
configDir: configDir,
Expand Down
97 changes: 96 additions & 1 deletion microceph/ceph/configwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func (s *configWriterSuite) TestWriteCephConfig() {
}

// Test ceph config writing
func (s *configWriterSuite) TestWriteRadosGWConfig() {
func (s *configWriterSuite) TestWriteRadosGWNonSSLConfig() {
config := newRadosGWConfig(s.Tmp)
err := config.WriteConfig(
map[string]any{
"monitors": "foohost",
"rgwPort": 80,
},
0644,
)
Expand All @@ -61,6 +62,100 @@ func (s *configWriterSuite) TestWriteRadosGWConfig() {
data, err := os.ReadFile(config.GetPath())
assert.Equal(s.T(), nil, err)
assert.Contains(s.T(), string(data), "foohost")
assert.Contains(s.T(), string(data), "rgw frontends = beast port=80\n")
}

// Test ceph config writing
func (s *configWriterSuite) TestWriteRadosGWCompleteConfig() {
config := newRadosGWConfig(s.Tmp)
err := config.WriteConfig(
map[string]any{
"monitors": "foohost",
"rgwPort": 80,
"sslPort": 443,
"sslCertificatePath": "/tmp/server.crt",
"sslPrivateKeyPath": "/tmp/server.key",
},
0644,
)
assert.Equal(s.T(), nil, err)
// Check that the file exists
_, err = os.Stat(config.GetPath())
assert.Equal(s.T(), nil, err)
// Check contents of the file
data, err := os.ReadFile(config.GetPath())
assert.Equal(s.T(), nil, err)
assert.Contains(s.T(), string(data), "foohost")
assert.Contains(s.T(), string(data), "rgw frontends = beast port=80 ssl_port=443 ssl_certificate=/tmp/server.crt ssl_private_key=/tmp/server.key")
}

func (s *configWriterSuite) TestWriteRadosGWSSLOnlyConfig() {
config := newRadosGWConfig(s.Tmp)
err := config.WriteConfig(
map[string]any{
"monitors": "foohost",
"rgwPort": 0,
"sslPort": 443,
"sslCertificatePath": "/tmp/server.crt",
"sslPrivateKeyPath": "/tmp/server.key",
},
0644,
)
assert.Equal(s.T(), nil, err)
// Check that the file exists
_, err = os.Stat(config.GetPath())
assert.Equal(s.T(), nil, err)
// Check contents of the file
data, err := os.ReadFile(config.GetPath())
assert.Equal(s.T(), nil, err)
assert.Contains(s.T(), string(data), "foohost")
assert.Contains(s.T(), string(data), "rgw frontends = beast ssl_port=443 ssl_certificate=/tmp/server.crt ssl_private_key=/tmp/server.key")
}

func (s *configWriterSuite) TestWriteRadosGWWithMissingSSLCertificateConfig() {
config := newRadosGWConfig(s.Tmp)
err := config.WriteConfig(
map[string]any{
"monitors": "foohost",
"rgwPort": 80,
"sslPort": 443,
"sslCertificatePath": "",
"sslPrivateKeyPath": "/tmp/server.key",
},
0644,
)
assert.Equal(s.T(), nil, err)
// Check that the file exists
_, err = os.Stat(config.GetPath())
assert.Equal(s.T(), nil, err)
// Check contents of the file
data, err := os.ReadFile(config.GetPath())
assert.Equal(s.T(), nil, err)
assert.Contains(s.T(), string(data), "foohost")
assert.Contains(s.T(), string(data), "rgw frontends = beast port=80\n")
}

func (s *configWriterSuite) TestWriteRadosGWWithMissingSSLPrivateKeyConfig() {
config := newRadosGWConfig(s.Tmp)
err := config.WriteConfig(
map[string]any{
"monitors": "foohost",
"rgwPort": 80,
"sslPort": 443,
"sslCertificatePath": "/tmp/server.crt",
"sslPrivateKeyPath": "",
},
0644,
)
assert.Equal(s.T(), nil, err)
// Check that the file exists
_, err = os.Stat(config.GetPath())
assert.Equal(s.T(), nil, err)
// Check contents of the file
data, err := os.ReadFile(config.GetPath())
assert.Equal(s.T(), nil, err)
assert.Contains(s.T(), string(data), "foohost")
assert.Contains(s.T(), string(data), "rgw frontends = beast port=80\n")
}

// Test ceph keyring writing
Expand Down
51 changes: 44 additions & 7 deletions microceph/ceph/rgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,52 @@ package ceph
import (
"context"
"database/sql"
"encoding/base64"
"fmt"
"github.com/canonical/microceph/microceph/constants"
"github.com/canonical/microceph/microceph/interfaces"
"os"
"path/filepath"
"strings"

"github.com/canonical/microceph/microceph/constants"
"github.com/canonical/microceph/microceph/interfaces"

"github.com/canonical/microceph/microceph/database"
)

// EnableRGW enables the RGW service on the cluster and adds initial configuration given a service port number.
func EnableRGW(s interfaces.StateInterface, port int, monitors []string) error {
func EnableRGW(s interfaces.StateInterface, port int, sslPort int, sslCertificate string, sslPrivateKey string, monitors []string) error {
pathConsts := constants.GetPathConst()

sslCertificatePath := ""
sslPrivateKeyPath := ""
if sslCertificate != "" && sslPrivateKey != "" {
sslCertificatePath = filepath.Join(pathConsts.SSLFilesPath, "server.crt")
decodedSSLCertificate, err := base64.StdEncoding.DecodeString(sslCertificate)
if err != nil {
return err
}
err = os.WriteFile(sslCertificatePath, decodedSSLCertificate, 0600)
if err != nil {
return err
}
sslPrivateKeyPath = filepath.Join(pathConsts.SSLFilesPath, "server.key")
decodedSSLPrivateKey, err := base64.StdEncoding.DecodeString(sslPrivateKey)
if err != nil {
return err
}
err = os.WriteFile(sslPrivateKeyPath, decodedSSLPrivateKey, 0600)
if err != nil {
return err
}
} else if sslCertificate == "" || sslPrivateKey == "" {
port = 80
}
configs := map[string]any{
"runDir": pathConsts.RunPath,
"monitors": strings.Join(monitors, ","),
"rgwPort": port,
"runDir": pathConsts.RunPath,
"monitors": strings.Join(monitors, ","),
"rgwPort": port,
"sslPort": sslPort,
"sslCertificatePath": sslCertificatePath,
"sslPrivateKeyPath": sslPrivateKeyPath,
}

// Create RGW configuration.
Expand Down Expand Up @@ -73,6 +100,16 @@ func DisableRGW(s interfaces.StateInterface) error {
return fmt.Errorf("failed to remove RGW keyring: %w", err)
}

// Remove the SSL files.
err = os.Remove(filepath.Join(pathConsts.SSLFilesPath, "server.crt"))
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove RGW SSL Certificate file: %w", err)
}
err = os.Remove(filepath.Join(pathConsts.SSLFilesPath, "server.key"))
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove RGW SSL Private Key file: %w", err)
}

// Remove the configuration.
err = os.Remove(filepath.Join(pathConsts.ConfPath, "radosgw.conf"))
if err != nil {
Expand Down
92 changes: 90 additions & 2 deletions microceph/ceph/rgw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type rgwSuite struct {
TestStateInterface *mocks.StateInterface
}

const validSSLCertificate = `LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURuakNDQW9hZ0F3SUJBZ0lVR0czNU9mWkcrRFdFQytrc2FHalJyTmlXZncwd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1hERUxNQWtHQTFVRUJoTUNWVk14RHpBTkJnTlZCQWdNQmtSbGJtbGhiREVVTUJJR0ExVUVCd3dMVTNCeQphVzVuWm1sbGJHUXhEREFLQmdOVkJBb01BMFJwY3pFWU1CWUdBMVVFQXd3UGQzZDNMbVY0WVcxd2JHVXVZMjl0Ck1CNFhEVEkwTURneE5qRTROREUxT0ZvWERUSTFNRGd4TmpFNE5ERTFPRm93WERFTE1Ba0dBMVVFQmhNQ1ZWTXgKRHpBTkJnTlZCQWdNQmtSbGJtbGhiREVVTUJJR0ExVUVCd3dMVTNCeWFXNW5abWxsYkdReEREQUtCZ05WQ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llSEp6Q0U1L3Q5SExxeVorZWt0Ym9rTWJhS3NVOGNGQlZnSlM3dEY0R29OMG8rbEVLQ3V3dm96S0hhbHcKMVRsTGhrUXFWRDhEaGNPS1hOb1dKS1RBME9LM1ZIMzVvc1VnOW41aEFvR0FYYm45dHNOVFp1SmpLWXFxMWszVQovM2trR0NadEJnZmEvaCtpRWdPN1RoZFp5ekdzcjRuVGkzQTFyU09iVkZ0amoza3BOTEZCMW91aTVMcEJjMWFWCkQ0VjhuMHhDdktJbTl2N2hCVm9iTWZVZmVoVE1TSFBZOFZvcWJneXY4ZWZueS9MNVh6d2R3b0NXSGpEZFZXS3EKMVlDLzBIRkhlRFJzWm9aT3RtdTVnTTQ9Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0=`

func TestRGW(t *testing.T) {
suite.Run(t, new(rgwSuite))
}
Expand Down Expand Up @@ -67,16 +70,101 @@ func (s *rgwSuite) TestEnableRGW() {

processExec = r

err := EnableRGW(s.TestStateInterface, 80, []string{"10.1.1.1", "10.2.2.2"})
err := EnableRGW(s.TestStateInterface, 80, 443, "", "", []string{"10.1.1.1", "10.2.2.2"})

assert.NoError(s.T(), err)

// check that the radosgw.conf file contains expected values
conf := s.ReadCephConfig("radosgw.conf")
assert.Contains(s.T(), conf, "rgw frontends = beast port=80")
assert.Contains(s.T(), conf, "rgw frontends = beast port=80\n")
assert.Contains(s.T(), conf, "mon host = 10.1.1.1,10.2.2.2")
}

// Test enabling RGW
func (s *rgwSuite) TestEnableRGWWithInvalidSSLCertificate() {
r := mocks.NewRunner(s.T())

processExec = r

err := EnableRGW(s.TestStateInterface, 80, 443, "invalid-certificate", validSSLPrivateKey, []string{"10.1.1.1", "10.2.2.2"})

// we expect an illegal base64 data error
assert.EqualError(s.T(), err, "illegal base64 data at input byte 7")

// check that the radosgw.conf file contains expected values
conf := s.ReadCephConfig("radosgw.conf")
assert.Equal(s.T(), conf, "")
}

// Test enabling RGW
func (s *rgwSuite) TestEnableRGWWithInvalidSSLPrivateKey() {
r := mocks.NewRunner(s.T())

processExec = r

err := EnableRGW(s.TestStateInterface, 80, 443, validSSLCertificate, "invalid-private-key", []string{"10.1.1.1", "10.2.2.2"})

// we expect an illegal base64 data error
assert.EqualError(s.T(), err, "illegal base64 data at input byte 7")

// check that the radosgw.conf file contains expected values
conf := s.ReadCephConfig("radosgw.conf")
assert.Equal(s.T(), conf, "")
}

// Test enabling RGW
func (s *rgwSuite) TestEnableRGWWithMissingSSLCertificate() {
r := mocks.NewRunner(s.T())

addRGWEnableExpectations(r)

processExec = r

err := EnableRGW(s.TestStateInterface, 0, 443, "", validSSLPrivateKey, []string{"10.1.1.1", "10.2.2.2"})

assert.NoError(s.T(), err)

// check that the radosgw.conf file contains expected values
conf := s.ReadCephConfig("radosgw.conf")
assert.Contains(s.T(), conf, "rgw frontends = beast port=80\n")
}

// Test enabling RGW
func (s *rgwSuite) TestEnableRGWWithMissingSSLPrivateKey() {
r := mocks.NewRunner(s.T())

addRGWEnableExpectations(r)

processExec = r

err := EnableRGW(s.TestStateInterface, 0, 443, validSSLCertificate, "", []string{"10.1.1.1", "10.2.2.2"})

assert.NoError(s.T(), err)

// check that the radosgw.conf file contains expected values
conf := s.ReadCephConfig("radosgw.conf")
assert.Contains(s.T(), conf, "rgw frontends = beast port=80\n")
}

// Test enabling RGW
func (s *rgwSuite) TestEnableRGWWithSSL() {
r := mocks.NewRunner(s.T())

addRGWEnableExpectations(r)

processExec = r

err := EnableRGW(s.TestStateInterface, 80, 443, validSSLCertificate, validSSLPrivateKey, []string{"10.1.1.1", "10.2.2.2"})

assert.NoError(s.T(), err)

// check that the radosgw.conf file contains expected values
conf := s.ReadCephConfig("radosgw.conf")
sslCertificatePath := filepath.Join(s.Tmp, "SNAP_COMMON", "server.crt")
sslPrivateKeyPath := filepath.Join(s.Tmp, "SNAP_COMMON", "server.key")
assert.Contains(s.T(), conf, "rgw frontends = beast port=80 ssl_port=443 ssl_certificate="+sslCertificatePath+" ssl_private_key="+sslPrivateKeyPath+"\n")
}

func (s *rgwSuite) TestDisableRGW() {
r := mocks.NewRunner(s.T())

Expand Down
7 changes: 5 additions & 2 deletions microceph/ceph/services_placement_rgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import (
)

type RgwServicePlacement struct {
Port int
Port int
SSLPort int
SSLCertificate string
SSLPrivateKey string
}

func (rgw *RgwServicePlacement) PopulateParams(s interfaces.StateInterface, payload string) error {
Expand All @@ -32,7 +35,7 @@ func (rgw *RgwServicePlacement) ServiceInit(s interfaces.StateInterface) error {
return fmt.Errorf("failed to get config db: %w", err)
}

return EnableRGW(s, rgw.Port, getMonitorAddresses(config))
return EnableRGW(s, rgw.Port, rgw.SSLPort, rgw.SSLCertificate, rgw.SSLPrivateKey, getMonitorAddresses(config))
}

func (rgw *RgwServicePlacement) PostPlacementCheck(s interfaces.StateInterface) error {
Expand Down
Loading
Loading