Skip to content

Commit

Permalink
Enable SSH Host certificate for AWS EC2 instances
Browse files Browse the repository at this point in the history
Use same default values in GCP and AWS, and support disable SSH host
certificate requests from config.

Signed-off-by: Eirik Nygaard <eirik@ngrd.no>
  • Loading branch information
ean committed Jun 10, 2024
1 parent 049b37f commit 7c238fb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
32 changes: 25 additions & 7 deletions provider/aws/sia-ec2/cmd/siad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ package main
import (
"flag"
"fmt"
"github.com/AthenZ/athenz/libs/go/sia/aws/options"
"github.com/AthenZ/athenz/libs/go/sia/util"
"github.com/AthenZ/athenz/provider/aws/sia-ec2"
"log"
"os"
"strings"

"github.com/AthenZ/athenz/libs/go/sia/aws/agent"
"github.com/AthenZ/athenz/libs/go/sia/aws/options"
"github.com/AthenZ/athenz/libs/go/sia/ssh/hostkey"
"github.com/AthenZ/athenz/libs/go/sia/util"
"github.com/AthenZ/athenz/provider/aws/sia-ec2"
)

// Following can be set by the build script using LDFLAGS

var Version string

const siaMainDir = "/var/lib/sia"
const sshDir = "/etc/ssh"

func main() {
cmd := flag.String("cmd", "", "optional sub command to run")
Expand Down Expand Up @@ -103,7 +105,7 @@ func main() {
}

opts.MetaEndPoint = *ec2MetaEndPoint
opts.Ssh = false
opts.Ssh = true
opts.EC2Document = string(document)
opts.EC2Signature = string(signature)
opts.PrivateIp = privateIp
Expand All @@ -117,17 +119,33 @@ func main() {
}
opts.Provider = provider

//check to see if this is ecs on ec2 and update instance id
//for ec2 instances we also need to set the start time so
//can check the expiry check if requested
disableSsh := false
// check to see if this is ecs on ec2 and update instance id
// for ec2 instances we also need to set the start time so
// can check the expiry check if requested
taskId := sia.GetECSOnEC2TaskId()
if taskId != "" {
opts.InstanceId = taskId
disableSsh = true
} else {
opts.EC2StartTime = startTime
opts.InstanceId = instanceId
}

if disableSsh {
opts.Ssh = false
} else if config != nil && config.Ssh != nil {
opts.Ssh = *config.Ssh
}

hostKeyType := hostkey.Ecdsa
if config != nil && config.SshHostKeyType != 0 {
hostKeyType = config.SshHostKeyType
}
opts.SshHostKeyType = hostKeyType
opts.SshCertFile = hostkey.CertFile(sshDir, opts.SshHostKeyType)
opts.SshPubKeyFile = hostkey.PubKeyFile(sshDir, opts.SshHostKeyType)

if *udsPath != "" {
opts.SDSUdsPath = *udsPath
}
Expand Down
11 changes: 10 additions & 1 deletion provider/gcp/sia-gce/cmd/siad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,16 @@ func main() {
// Better defaults
opts.RotateKey = true
opts.GenerateRoleKey = true
opts.SshHostKeyType = hostkey.Ecdsa

if config != nil && config.Ssh != nil {
opts.Ssh = *config.Ssh
}

hostKeyType := hostkey.Ecdsa
if config != nil && config.SshHostKeyType != 0 {
hostKeyType = config.SshHostKeyType
}
opts.SshHostKeyType = hostKeyType
opts.SshCertFile = hostkey.CertFile(sshDir, opts.SshHostKeyType)
opts.SshPubKeyFile = hostkey.PubKeyFile(sshDir, opts.SshHostKeyType)

Expand Down

0 comments on commit 7c238fb

Please sign in to comment.