Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
Sep 8, 2023

Conversation

spikecurtis
Copy link
Contributor

fixes #9544

Adds support for (but does not enable) networked provisioners.

Comment on lines +119 to +148
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
}
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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]>
@spikecurtis spikecurtis enabled auto-merge (squash) September 8, 2023 09:44
Signed-off-by: Spike Curtis <[email protected]>
@spikecurtis spikecurtis merged commit 11b6068 into main Sep 8, 2023
@spikecurtis spikecurtis deleted the spike/9544-networked-provisioners branch September 8, 2023 09:53
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Provisioner Daemon - Provisioner to connect over a network
2 participants