Skip to content

Commit 480a305

Browse files
authored
change dir file perms (#439)
* change dir file perms * output as sarif
1 parent 5a6e417 commit 480a305

File tree

2 files changed

+64
-18
lines changed

2 files changed

+64
-18
lines changed

.github/workflows/gosec.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
uses: actions/checkout@v4
2222

2323
- name: Run Gosec Security Scanner
24-
uses: securego/gosec@master
24+
uses: securego/gosec@v2.20.0
2525
with:
26-
args: ./...
26+
args: '-no-fail -fmt sarif -out results.sarif ./...'
27+
- name: Upload SARIF file
28+
uses: github/codeql-action/upload-sarif@v3
29+
with:
30+
sarif_file: results.sarif

examples/falcon_sensor_download/main.go

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,49 @@ import (
1717
)
1818

1919
func main() {
20-
clientId := flag.String("client-id", os.Getenv("FALCON_CLIENT_ID"), "Client ID for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_ID env)")
21-
clientSecret := flag.String("client-secret", os.Getenv("FALCON_CLIENT_SECRET"), "Client Secret for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_SECRET)")
22-
memberCID := flag.String("member-cid", os.Getenv("FALCON_MEMBER_CID"), "Member CID for MSSP (for cases when OAuth2 authenticates multiple CIDs)")
23-
clientCloud := flag.String("cloud", os.Getenv("FALCON_CLOUD"), "Falcon cloud abbreviation (us-1, us-2, eu-1, us-gov-1)")
20+
clientId := flag.String(
21+
"client-id",
22+
os.Getenv("FALCON_CLIENT_ID"),
23+
"Client ID for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_ID env)",
24+
)
25+
clientSecret := flag.String(
26+
"client-secret",
27+
os.Getenv("FALCON_CLIENT_SECRET"),
28+
"Client Secret for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_SECRET)",
29+
)
30+
memberCID := flag.String(
31+
"member-cid",
32+
os.Getenv("FALCON_MEMBER_CID"),
33+
"Member CID for MSSP (for cases when OAuth2 authenticates multiple CIDs)",
34+
)
35+
clientCloud := flag.String(
36+
"cloud",
37+
os.Getenv("FALCON_CLOUD"),
38+
"Falcon cloud abbreviation (us-1, us-2, eu-1, us-gov-1)",
39+
)
2440
osName := flag.String("os-name", "", "Name of the operating system")
2541
osVersion := flag.String("os-version", "", "Versin of the operating system")
26-
sensorVersion := flag.String("sensor-version", "latest", "Version of the Falcon Sensor. Use: 'latest' to get the latest or '' to get prompted interactively")
42+
sensorVersion := flag.String(
43+
"sensor-version",
44+
"latest",
45+
"Version of the Falcon Sensor. Use: 'latest' to get the latest or '' to get prompted interactively",
46+
)
2747

2848
all := flag.Bool("all", false, "Download all sensors")
2949

3050
flag.Parse()
3151

3252
if *clientId == "" {
33-
*clientId = falcon_util.PromptUser(`Missing FALCON_CLIENT_ID environment variable. Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
34-
Falcon Client ID`)
53+
*clientId = falcon_util.PromptUser(
54+
`Missing FALCON_CLIENT_ID environment variable. Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
55+
Falcon Client ID`,
56+
)
3557
}
3658
if *clientSecret == "" {
37-
*clientSecret = falcon_util.PromptUser(`Missing FALCON_CLIENT_SECRET environment variable. Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
38-
Falcon Client Secret`)
59+
*clientSecret = falcon_util.PromptUser(
60+
`Missing FALCON_CLIENT_SECRET environment variable. Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
61+
Falcon Client Secret`,
62+
)
3963
}
4064

4165
client, err := falcon.NewClient(&falcon.ApiConfig{
@@ -92,7 +116,11 @@ Falcon Client Secret`)
92116
}
93117
}
94118

95-
func download(client *client.CrowdStrikeAPISpecification, sensor *models.DomainSensorInstallerV1, dir, filename string) {
119+
func download(
120+
client *client.CrowdStrikeAPISpecification,
121+
sensor *models.DomainSensorInstallerV1,
122+
dir, filename string,
123+
) {
96124
file, err := openFileForWriting(dir, filename)
97125
if err != nil {
98126
panic(err)
@@ -114,7 +142,10 @@ func download(client *client.CrowdStrikeAPISpecification, sensor *models.DomainS
114142
fmt.Printf("Downloaded %s to %s\n", *sensor.Description, filename)
115143
}
116144

117-
func querySuitableSensor(client *client.CrowdStrikeAPISpecification, osName, osVersion, sensorVersion string) *models.DomainSensorInstallerV1 {
145+
func querySuitableSensor(
146+
client *client.CrowdStrikeAPISpecification,
147+
osName, osVersion, sensorVersion string,
148+
) *models.DomainSensorInstallerV1 {
118149
for _, sensor := range getSensors(client, osName) {
119150
if osVersion == *sensor.OsVersion {
120151
if *sensor.Version == sensorVersion || sensorVersion == "latest" {
@@ -125,7 +156,10 @@ func querySuitableSensor(client *client.CrowdStrikeAPISpecification, osName, osV
125156
return nil
126157
}
127158

128-
func getSensors(client *client.CrowdStrikeAPISpecification, osName string) []*models.DomainSensorInstallerV1 {
159+
func getSensors(
160+
client *client.CrowdStrikeAPISpecification,
161+
osName string,
162+
) []*models.DomainSensorInstallerV1 {
129163
var filter *string
130164
if osName != "" {
131165
f := fmt.Sprintf("os:\"%s\"", osName)
@@ -184,7 +218,10 @@ func getValidOsVersions(client *client.CrowdStrikeAPISpecification, osName strin
184218
return list
185219
}
186220

187-
func getValidSensorVersions(client *client.CrowdStrikeAPISpecification, osName, osVersion string) []string {
221+
func getValidSensorVersions(
222+
client *client.CrowdStrikeAPISpecification,
223+
osName, osVersion string,
224+
) []string {
188225
sensors := getSensors(client, osName)
189226
sensorVersions := make(map[string]void)
190227
for _, sensor := range sensors {
@@ -202,9 +239,12 @@ func getValidSensorVersions(client *client.CrowdStrikeAPISpecification, osName,
202239

203240
func downloadAllSensors(client *client.CrowdStrikeAPISpecification) {
204241
for sensor := range oneSensorPerOsVersion(client) {
205-
dir := filepath.Join(strings.ReplaceAll(*sensor.Os, "/", "-"), strings.ReplaceAll(*sensor.OsVersion, "/", "-"))
242+
dir := filepath.Join(
243+
strings.ReplaceAll(*sensor.Os, "/", "-"),
244+
strings.ReplaceAll(*sensor.OsVersion, "/", "-"),
245+
)
206246
if dir != "" {
207-
err := os.MkdirAll(dir, os.ModePerm)
247+
err := os.MkdirAll(dir, 0750)
208248
if err != nil {
209249
panic(fmt.Sprintf("Could not create directory %s: %v", dir, err))
210250
}
@@ -213,7 +253,9 @@ func downloadAllSensors(client *client.CrowdStrikeAPISpecification) {
213253
}
214254
}
215255

216-
func oneSensorPerOsVersion(client *client.CrowdStrikeAPISpecification) <-chan *models.DomainSensorInstallerV1 {
256+
func oneSensorPerOsVersion(
257+
client *client.CrowdStrikeAPISpecification,
258+
) <-chan *models.DomainSensorInstallerV1 {
217259
out := make(chan *models.DomainSensorInstallerV1)
218260

219261
sensors, err := client.SensorDownload.GetCombinedSensorInstallersByQuery(

0 commit comments

Comments
 (0)