-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work on refactoring and documentation of ECS
Fixes: #938
- Loading branch information
1 parent
3bb3185
commit 9c02e64
Showing
10 changed files
with
292 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Dockerfile* | ||
dist/* | ||
*.crt | ||
*.key | ||
tags | ||
coverage.out | ||
aws-ssl-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package main | ||
|
||
/* | ||
* AWS SSO CLI | ||
* Copyright (c) 2021-2024 Aaron Turner <synfinatic at gmail dot com> | ||
* | ||
* This program is free software: you can redistribute it | ||
* and/or modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or with the authors permission any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"os" | ||
|
||
"github.com/synfinatic/aws-sso-cli/internal/ecs" | ||
"github.com/synfinatic/aws-sso-cli/internal/ecs/server" | ||
) | ||
|
||
type EcsServerCmd struct { | ||
BindIP string `kong:"help='Bind address for ECS Server',env='AWS_SSO_ECS_BIND',default='127.0.0.1'"` | ||
Port int `kong:"help='TCP port to listen on',env='AWS_SSO_ECS_PORT',default=4144"` | ||
// hidden flags are for internal use only when running in a docker container | ||
Docker bool `kong:"hidden"` | ||
DisableSSL bool `kong:"help='Disable SSL/TLS for the ECS Server'"` | ||
} | ||
|
||
func (cc *EcsServerCmd) Run(ctx *RunContext) error { | ||
// Start the ECS Server | ||
bindIP := ctx.Cli.Ecs.Server.BindIP | ||
if ctx.Cli.Ecs.Server.Docker { | ||
// if running in a docker container, bind to all interfaces | ||
bindIP = "0.0.0.0" | ||
} | ||
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", bindIP, ctx.Cli.Ecs.Server.Port)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var bearerToken, privateKey, certChain string | ||
if ctx.Cli.Ecs.Server.Docker { | ||
// fetch the creds from our temporary file mounted in the docker container | ||
f, err := ecs.OpenSecurityFile(ecs.READ_ONLY) | ||
if err != nil { | ||
log.Warnf("Failed to open ECS credentials file: %s", err.Error()) | ||
} else { | ||
creds, err := ecs.ReadSecurityConfig(f) | ||
if err != nil { | ||
return err | ||
} | ||
// have to manually close since defer won't work in this case | ||
f.Close() | ||
os.Remove(f.Name()) | ||
|
||
bearerToken = creds.BearerToken | ||
privateKey = creds.PrivateKey | ||
certChain = creds.CertChain | ||
} | ||
} else { | ||
if bearerToken, err = ctx.Store.GetEcsBearerToken(); err != nil { | ||
return err | ||
} | ||
|
||
if privateKey, err = ctx.Store.GetEcsSslKey(); err != nil { | ||
return err | ||
} else if privateKey != "" { | ||
// only get the certificate if the private key is set | ||
if certChain, err = ctx.Store.GetEcsSslCert(); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
if bearerToken == "" { | ||
log.Warnf("HTTP Auth: disabled. Use 'aws-sso ecs bearer-token' to enable") | ||
} else { | ||
log.Info("HTTP Auth: enabled") | ||
} | ||
|
||
// Disable SSL, even if configure | ||
if ctx.Cli.Ecs.Server.DisableSSL { | ||
privateKey = "" | ||
certChain = "" | ||
} | ||
|
||
if privateKey != "" && certChain != "" { | ||
log.Infof("SSL/TLS: enabled") | ||
} else { | ||
log.Warnf("SSL/TLS: disabled. Use 'aws-sso ecs cert' to enable") | ||
} | ||
|
||
s, err := server.NewEcsServer(context.TODO(), bearerToken, l, privateKey, certChain) | ||
if err != nil { | ||
return err | ||
} | ||
return s.Serve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.