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

Enable SSH Host certificate for AWS EC2 instances #2635

Merged
merged 1 commit into from
Jun 23, 2024
Merged
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
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