Skip to content

Commit

Permalink
Merge pull request #27 from josemotafbn/feature/CspmUrlFix
Browse files Browse the repository at this point in the history
Add support for CSPM urls for different regions to the Trivy Docker Extension
  • Loading branch information
tonaim committed Jul 27, 2023
2 parents efa9262 + fcb128a commit 0686035
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
8 changes: 7 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SendMetric } from './Metrics';
export function App() {
const [aquaKey, setAquaKey] = React.useState("");
const [aquaSecret, setAquaSecret] = React.useState("");
const [aquaCSPMUrl, setAquaCSPMUrl] = React.useState("");

const [scanImage, setScanImage] = React.useState("");
const [disableScan, setDisableScan] = React.useState(true);
Expand Down Expand Up @@ -135,6 +136,8 @@ export function App() {
commandParts.push("AQUA_KEY=" + aquaKey);
commandParts.push("-e");
commandParts.push("AQUA_SECRET=" + aquaSecret);
commandParts.push("-e");
commandParts.push("CSPM_URL=" + aquaCSPMUrl);
}


Expand Down Expand Up @@ -338,7 +341,8 @@ export function App() {
window.ddClient.extension.vm.service.get("/credentials").then((value: any) => {
setAquaKey(value.aqua_key);
setAquaSecret(value.aqua_secret);
if (value.aqua_key !== "" && value.aqua_secret !== "") {
setAquaCSPMUrl(value.aqua_cspm_url);
if (value.aqua_key !== "" && value.aqua_secret !== "" && value.aqua_cspm_url !== "") {
setLoggedIn(true);
}
}).catch((err: any) => {
Expand All @@ -360,6 +364,8 @@ export function App() {
setAquaKey={setAquaKey}
aquaSecret={aquaSecret}
setAquaSecret={setAquaSecret}
aquaCSPMUrl={aquaCSPMUrl}
setAquaCSPMUrl={setAquaCSPMUrl}
loggedIn={loggedIn}
setLoggedIn={setLoggedIn}
/>
Expand Down
19 changes: 16 additions & 3 deletions client/src/ConfigureCreds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ConfigureCreds(props: any) {
};

const handleSaveDetails = () => {
let payload = { aqua_key: props.aquaKey, aqua_secret: props.aquaSecret };
let payload = { aqua_key: props.aquaKey, aqua_secret: props.aquaSecret, aqua_cspm_url: props.aquaCSPMUrl };
console.log(payload);
window.ddClient.extension.vm.service.request({ url: "/credentials", method: "POST", headers: { 'Content-Type': 'application/json' }, data: payload })
.then(() => {
Expand All @@ -41,13 +41,15 @@ export function ConfigureCreds(props: any) {
SendMetric("trivy_aqua_login_failed", { aquaKey: props.aquaKey });
props.setAquaKey("");
props.setAquaSecret("");
props.setAquaCSPMUrl("");
console.log(error);
});
};

const handleSignOutClick = () => {
props.setAquaKey("");
props.setAquaSecret("");
props.setAquaCSPMUrl("");
props.setLoggedIn(false);

let payload = { aqua_key: "", aqua_secret: "" };
Expand Down Expand Up @@ -94,7 +96,7 @@ export function ConfigureCreds(props: any) {
onChange={(e) => props.setAquaKey(e.target.value)}
fullWidth
variant="standard"
helperText="AQUA_KEY provided in you CSPM account"
helperText="AQUA_KEY provided in your CSPM account"
/>
<TextField
margin="dense"
Expand All @@ -105,8 +107,19 @@ export function ConfigureCreds(props: any) {
onChange={(e) => props.setAquaSecret(e.target.value)}
fullWidth
variant="standard"
helperText="AQUA_SECRET provided in you CSPM account"
helperText="AQUA_SECRET provided in your CSPM account"
/>
<TextField
margin="dense"
id="aquaCSPMUrl"
label="Aqua CSPM Url"
type="text"
value={props.aquaCSPMUrl}
onChange={(e) => props.setAquaCSPMUrl(e.target.value)}
fullWidth
variant="standard"
helperText="AQUA_CSPM_URL provided in your CSPM account"
/>

</DialogContent>
<DialogActions>
Expand Down
6 changes: 3 additions & 3 deletions service/internal/auth/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type Response struct {
Errors []string `json:"errors,omitempty"`
}

const cspmUrl = "https://api.cloudsploit.com/v2/tokens"
const cspmTokenExchangePath = "/v2/tokens"

func ValidateCredentials(key, secret string) (string, error) {
func ValidateCredentials(key, secret, cspmUrl string) (string, error) {
body := `{"validity":30,"allowed_endpoints":["ANY:v2/build/twirp/buildsecurity.BuildSecurity/*"]}`

req, err := http.NewRequest("POST", cspmUrl, bytes.NewBuffer([]byte(body)))
req, err := http.NewRequest("POST", cspmUrl+cspmTokenExchangePath, bytes.NewBuffer([]byte(body)))
if err != nil {
return "", err
}
Expand Down
7 changes: 4 additions & 3 deletions service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
const credsFile = "/creds/.aqua"

type Credentials struct {
AquaKey string `json:"aqua_key"`
AquaSecret string `json:"aqua_secret"`
AquaKey string `json:"aqua_key"`
AquaSecret string `json:"aqua_secret"`
AquaCSPMUrl string `json:"aqua_cspm_url"`
}

func main() {
Expand Down Expand Up @@ -66,7 +67,7 @@ func writeCredentials(ctx echo.Context) error {
if err := ctx.Bind(creds); err != nil {
return internalError(ctx, err)
}
validated, err := auth.ValidateCredentials(creds.AquaKey, creds.AquaSecret)
validated, err := auth.ValidateCredentials(creds.AquaKey, creds.AquaSecret, creds.AquaCSPMUrl)
if err != nil || validated == "" {
return internalError(ctx, err)
}
Expand Down

0 comments on commit 0686035

Please sign in to comment.