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

MGMT-18684: Ensure that bootstrap CSR is authenticated against cluster hosts. #895

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/coreos/ignition/v2 v2.18.0
github.com/go-openapi/runtime v0.28.0
github.com/go-openapi/strfmt v0.23.0
github.com/go-openapi/swag v0.23.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.6.0
github.com/kelseyhightower/envconfig v1.4.0
Expand Down Expand Up @@ -82,6 +81,7 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
Expand Down
6 changes: 3 additions & 3 deletions src/assisted_installer_controller/reboots_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/openshift/assisted-installer/src/common"
"github.com/openshift/assisted-installer/src/convert"
"github.com/openshift/assisted-installer/src/inventory_client"
"github.com/openshift/assisted-installer/src/ops"
"github.com/openshift/assisted-installer/src/utils"
Expand Down Expand Up @@ -97,8 +97,8 @@ func (r *rebootsNotifier) run(ctx context.Context, nodeName string, hostId, infr
ClusterID: clusterId,
Name: eventName,
Category: models.EventCategoryUser,
Severity: swag.String(models.EventSeverityInfo),
Message: swag.String(fmt.Sprintf(eventMessageTemplate, nodeName, numberOfReboots)),
Severity: convert.String(models.EventSeverityInfo),
Message: convert.String(fmt.Sprintf(eventMessageTemplate, nodeName, numberOfReboots)),
}

if err = r.ic.TriggerEvent(ctx, ev); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/assisted_installer_controller/reboots_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"

"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/google/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/assisted-installer/src/convert"
"github.com/openshift/assisted-installer/src/inventory_client"
"github.com/openshift/assisted-installer/src/ops"
"github.com/openshift/assisted-service/models"
Expand Down Expand Up @@ -71,9 +71,9 @@ var _ = Describe("Reboots notifier", func() {
ClusterID: &clusterId,
HostID: &hostId,
InfraEnvID: &infraenvId,
Message: swag.String(fmt.Sprintf(eventMessageTemplate, nodeName, 1)),
Message: convert.String(fmt.Sprintf(eventMessageTemplate, nodeName, 1)),
Name: eventName,
Severity: swag.String(models.EventSeverityInfo),
Severity: convert.String(models.EventSeverityInfo),
}).Return(nil)
notifier.Start(context.TODO(), nodeName, &hostId, &infraenvId, &clusterId)
notifier.Finalize()
Expand Down
26 changes: 26 additions & 0 deletions src/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package common
import (
"bytes"
"context"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/x509"
"encoding/pem"
"fmt"
"io"
"os"
Expand All @@ -16,6 +20,8 @@ import (
"github.com/openshift/assisted-installer/src/utils"
"github.com/openshift/assisted-service/models"

cryptorand "crypto/rand"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/thoas/go-funk"
Expand All @@ -35,6 +41,7 @@ const (
installConfigMapAttribute = "invoker"
InvokerAssisted = "assisted-service"
InvokerAgent = "agent-installer"
ECPrivateKeyPEMLabel = "EC PRIVATE KEY"
)

func GetHostsInStatus(hosts map[string]inventory_client.HostData, status []string, isMatch bool) map[string]inventory_client.HostData {
Expand Down Expand Up @@ -306,3 +313,22 @@ func DownloadKubeconfigNoingress(ctx context.Context, dir string, ic inventory_c

return kubeconfigPath, nil
}

func MakeEllipticPrivatePublicKeyPems() ([]byte, []byte, error) {
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), cryptorand.Reader)
if err != nil {
return nil, nil, err
}
derBytes, err := x509.MarshalECPrivateKey(privateKey)
if err != nil {
return nil, nil, err
}
publicKeyBytes, err := x509.MarshalPKIXPublicKey(&privateKey.PublicKey)
if err != nil {
return nil, nil, err
}
return pem.EncodeToMemory(&pem.Block{
Type: ECPrivateKeyPEMLabel,
Bytes: derBytes,
}), publicKeyBytes, nil
}
Loading