-
Notifications
You must be signed in to change notification settings - Fork 928
feat: add support for networked provisioners #9593
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
Conversation
Signed-off-by: Spike Curtis <[email protected]>
Signed-off-by: Spike Curtis <[email protected]>
func GenCert() (*ecdsa.PrivateKey, []byte, error) { | ||
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) | ||
if err != nil { | ||
return nil, nil, xerrors.Errorf("generate private key: %w", err) | ||
} | ||
template := x509.Certificate{ | ||
SerialNumber: big.NewInt(1), | ||
Subject: pkix.Name{ | ||
CommonName: "Coder Provisioner Daemon", | ||
}, | ||
DNSNames: []string{serverName}, | ||
NotBefore: time.Now(), | ||
// cert is valid for 5 years, which is much longer than we expect this | ||
// process to stay up. The idea is that the certificate is self-signed | ||
// and is valid for as long as the daemon is up and starting new remote | ||
// provisioners | ||
NotAfter: time.Now().Add(time.Hour * 24 * 365 * 5), | ||
|
||
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, | ||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, | ||
BasicConstraintsValid: true, | ||
} | ||
|
||
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &privateKey.PublicKey, privateKey) | ||
if err != nil { | ||
return nil, nil, xerrors.Errorf("failed to create certificate: %w", err) | ||
} | ||
cert := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) | ||
return privateKey, cert, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there's a few more instances where we generate a self-signed cert, we could perhaps extract a util function here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced it would save much trouble once we account for all the variable arguments
if !pt.Valid() { | ||
go errResponse(job, respCh, xerrors.Errorf("invalid provisioner type: %s", job.Provisioner)) | ||
} | ||
tb := make([]byte, 4) // 128-bit token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this 32 bits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops!
Signed-off-by: Spike Curtis <[email protected]>
Signed-off-by: Spike Curtis <[email protected]>
fixes #9544
Adds support for (but does not enable) networked provisioners.