Skip to content
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
9 changes: 3 additions & 6 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.26.x]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: ${{ matrix.go-version }}

- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: projectdiscovery/actions/setup/go@v1

- name: Build
run: go build .
working-directory: cmd/cloudlist/
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ jobs:
name: Lint Test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: 1.26.x
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: projectdiscovery/actions/setup/go@v1
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ jobs:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: 1.26.x
uses: projectdiscovery/actions/setup/go@v1

- name: release test
uses: goreleaser/goreleaser-action@v7
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
with:
fetch-depth: 0
- uses: projectdiscovery/actions/setup/go@v1
with:
go-version: 1.26.x

- uses: docker/login-action@v4
with:
Expand Down
4 changes: 3 additions & 1 deletion PROVIDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ References -

### Kubernetes

To integrate Kubernetes, utilize the configuration block outlined below. This block allows you to specify Kubernetes connection details either through a file path or directly by providing the encoded kubeconfig content. If both kubeconfig_file and kubeconfig_encoded are specified, the kubeconfig_encoded will take precedence. If neither is specified, the kubeconfig is resolved like kubectl: `$KUBECONFIG`, then `~/.kube/config`, then the in-cluster service account.
To integrate Kubernetes, utilize the configuration block outlined below. This block allows you to specify Kubernetes connection details either through a file path or directly by providing the encoded kubeconfig content. If both kubeconfig_file and kubeconfig_encoded are specified, the kubeconfig_encoded will take precedence. If neither is specified, the block fails unless `use_default_kubeconfig: true` is set, which resolves the kubeconfig like kubectl: `$KUBECONFIG` if set, otherwise `~/.kube/config`, otherwise the in-cluster service account.


```yaml
Expand All @@ -600,6 +600,8 @@ To integrate Kubernetes, utilize the configuration block outlined below. This bl
kubeconfig_file: path/to/kubeconfig
# Base64 encoded kubeconfig, $ cat $KUBECONFIG | base64
kubeconfig_encoded: <encoded-kubeconfig>
# Use the default kubeconfig lookup when neither kubeconfig_file nor kubeconfig_encoded is set (optional).
use_default_kubeconfig: true
# The context to use from the kubeconfig (optional). If omitted, the default is the current-context as defined in the kubeconfig.
context: <context-name>
```
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/projectdiscovery/cloudlist

go 1.26.0
go 1.26.10

require (
git.arvancloud.ir/arvancloud/cdn-go-sdk v0.12.1
Expand Down Expand Up @@ -179,8 +179,8 @@ require (
github.com/alitto/pond/v2 v2.3.2
github.com/dnsimple/dnsimple-go v1.7.0
github.com/ovh/go-ovh v1.9.0
github.com/projectdiscovery/networkpolicy v0.1.52
github.com/projectdiscovery/retryablehttp-go v1.3.29
github.com/projectdiscovery/networkpolicy v0.1.55
github.com/projectdiscovery/retryablehttp-go v1.3.31
)

require (
Expand All @@ -204,7 +204,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/ebitengine/purego v0.10.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gaissmai/bart v0.29.1 // indirect
github.com/gaissmai/bart v0.30.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
Expand All @@ -213,7 +213,7 @@ require (
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/projectdiscovery/fastdialer v0.5.23 // indirect
github.com/projectdiscovery/fastdialer v0.5.24 // indirect
github.com/projectdiscovery/hmap v0.0.102 // indirect
github.com/projectdiscovery/retryabledns v1.0.116 // indirect
github.com/refraction-networking/utls v1.8.2 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gaissmai/bart v0.29.1 h1:6cMnEsaqI+9uNVX+kIW5NMU7JE1lA8tHgccwNIetvV0=
github.com/gaissmai/bart v0.29.1/go.mod h1:GREWQfTLRWz/c5FTOsIw+KkscuFkIV5t8Rp7Nd1Td5c=
github.com/gaissmai/bart v0.30.0 h1:K1oTSQ6Nf76bhrgxeTqzZa4hE0M9x4xDfL6n6UG67Sc=
github.com/gaissmai/bart v0.30.0/go.mod h1:GREWQfTLRWz/c5FTOsIw+KkscuFkIV5t8Rp7Nd1Td5c=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
Expand Down Expand Up @@ -496,8 +496,8 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/projectdiscovery/blackrock v0.0.2 h1:mxXdu0uM8P2L2Qi210COlU8QiICPFW/Rxk5QUhlPO2k=
github.com/projectdiscovery/blackrock v0.0.2/go.mod h1:ANUtjDfaVrqB453bzToU+YB4cUbvBRpLvEwoWIwlTss=
github.com/projectdiscovery/fastdialer v0.5.23 h1:uL0ILvwrOv52BK4XXFM7CyakR+0d3tmc0m1R+i8NelI=
github.com/projectdiscovery/fastdialer v0.5.23/go.mod h1:psWXmdbZhGxmVLNP2o1YI93R8d2YtOwK5XSNhlWxXJ8=
github.com/projectdiscovery/fastdialer v0.5.24 h1:wA0E6UTKtfR+Uqrw5vSR5XUmYHK3IkVoGLrt8yojjbc=
github.com/projectdiscovery/fastdialer v0.5.24/go.mod h1:GybngvpSevg/48Kk/NgPw2HQOB95FngbOS93f1pTJ84=
github.com/projectdiscovery/goflags v0.2.1 h1:XnSYvsCjUwHbZaaJUZ3YznCJPoXRk/IhTFP9Gecmx6M=
github.com/projectdiscovery/goflags v0.2.1/go.mod h1:7nAP1r2Dqgn/rwmOE3EWbZWUCEJKNIhVSBGpuzJAIns=
github.com/projectdiscovery/gologger v1.1.73 h1:WX2nzq29cL7HdvOHqIttacoid/5lMwapyM7ukGU1jFY=
Expand All @@ -506,12 +506,12 @@ github.com/projectdiscovery/hmap v0.0.102 h1:ybPuf7UQvuOLiHLOUbVMvd+PSlItQU5iQpP
github.com/projectdiscovery/hmap v0.0.102/go.mod h1:IZ92wXFmxYpdn0euZ7VFmypzOBNDwq8c3yRyIIol6XE=
github.com/projectdiscovery/machineid v0.0.0-20250715113114-c77eb3567582 h1:eR+0HE//Ciyfwy3HC7fjRyKShSJHYoX2Pv7pPshjK/Q=
github.com/projectdiscovery/machineid v0.0.0-20250715113114-c77eb3567582/go.mod h1:3G3BRKui7nMuDFAZKR/M2hiOLtaOmyukT20g88qRQjI=
github.com/projectdiscovery/networkpolicy v0.1.52 h1:0mjGoggVSHgqgRLBZoU+rl3jRkQkgCKzLDtnb4pswoE=
github.com/projectdiscovery/networkpolicy v0.1.52/go.mod h1:Mdx5Y4x6b89P0Wz4Hu9yc/qhD7ZLJMdwOqMXwlLcqN8=
github.com/projectdiscovery/networkpolicy v0.1.55 h1:D30pipxOdWnSq3r7sX0kQvGyb18sUgopuda1j9NAmnQ=
github.com/projectdiscovery/networkpolicy v0.1.55/go.mod h1:N5bXm8L3UsDw51CeA1nhTsGEbQMbgL5lXTiIU013xd0=
github.com/projectdiscovery/retryabledns v1.0.116 h1:tK28PJ4tLO7bgM89RpIFjkfTPMSbRegwvg9mN/q6z78=
github.com/projectdiscovery/retryabledns v1.0.116/go.mod h1:r3vH0AKYtJ9fculcqRFrdVYe2ABcHwZeR4C6j3rqCbY=
github.com/projectdiscovery/retryablehttp-go v1.3.29 h1:lFHsqbXs1/fW8OnZObTXcYlAgsNOVk+z+dBixMHr3JI=
github.com/projectdiscovery/retryablehttp-go v1.3.29/go.mod h1:rVlVCNYP5JUNHNLD92VaU38BuNbj47RhLcpriBI6jl8=
github.com/projectdiscovery/retryablehttp-go v1.3.31 h1:0hSEZ5+jj6Oo1IL8qrytD36TK/qCxfe543jEaRqSTjs=
github.com/projectdiscovery/retryablehttp-go v1.3.31/go.mod h1:/WEa7YejxTCXEMLCGfGYaC3JsgXgzuqw8rv8cb4buEc=
github.com/projectdiscovery/utils v0.11.9 h1:aKLje3zPcZuOGmopN51PasWxPX/CypPwzP2ke/Qa2bA=
github.com/projectdiscovery/utils v0.11.9/go.mod h1:d3BcbsHhuxW9T3jpvrgzwshvqhaL9qPSkoi+3h/DY8E=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down
27 changes: 20 additions & 7 deletions internal/runner/autodiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ package runner

import (
"errors"
"fmt"
"strings"

"github.com/projectdiscovery/cloudlist/pkg/inventory"
"github.com/projectdiscovery/cloudlist/pkg/schema"
"github.com/projectdiscovery/gologger"
)

// autoDiscoveryProviders resolve credentials without config through their SDK
// default chains: environment variables, CLI logins, instance metadata and
// in-cluster service accounts.
// default credential chains.
var autoDiscoveryProviders = []string{"aws", "gcp", "azure", "kubernetes"}

func autoDiscoveryConfig() schema.Options {
config := make(schema.Options, 0, len(autoDiscoveryProviders))
for _, provider := range autoDiscoveryProviders {
config = append(config, schema.OptionBlock{"provider": provider})
block := schema.OptionBlock{"provider": provider}
if provider == "kubernetes" {
block["use_default_kubeconfig"] = "true"
}
config = append(config, block)
}
return config
}
Expand All @@ -25,19 +30,27 @@ func (r *Runner) newInventory(config schema.Options) (*inventory.Inventory, erro
if !r.options.AutoDiscovery {
return inventory.New(config)
}
// A provider fails to initialize when the environment has no credentials
// for it, which is expected here, so skip it instead of aborting.
if len(config) == 0 {
return nil, fmt.Errorf("no auto-discovery provider matches the -p/-id filters, supported: %s", strings.Join(autoDiscoveryProviders, ","))
}
// Init fails for missing credentials but also for denied, expired or
// unreachable ones, so skip failed providers and report why.
discovered := &inventory.Inventory{}
var errs []error
for _, block := range config {
inv, err := inventory.New(schema.Options{block})
if err != nil {
gologger.Verbose().Msgf("Skipping %s: %s", block["provider"], err)
errs = append(errs, err)
continue
}
discovered.Providers = append(discovered.Providers, inv.Providers...)
}
if len(discovered.Providers) == 0 {
return nil, errors.New("no provider credentials found in the environment")
return nil, fmt.Errorf("no provider could be initialized: %w", errors.Join(errs...))
}
for _, err := range errs {
// Info stays visible at the default log level. Warning is dropped unless -v is set.
gologger.Info().Msgf("Skipping provider: %s", err)
}
return discovered, nil
}
93 changes: 90 additions & 3 deletions internal/runner/autodiscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,52 @@ package runner
import (
"os"
"path/filepath"
"strings"
"testing"

"github.com/projectdiscovery/cloudlist/pkg/schema"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
"github.com/projectdiscovery/gologger/writer"
"github.com/stretchr/testify/require"
)

func TestNewInventorySkipsProvidersWithoutCredentials(t *testing.T) {
type logRecord struct {
message string
level levels.Level
}

type captureWriter struct {
records []logRecord
}

func (w *captureWriter) Write(data []byte, level levels.Level) {
w.records = append(w.records, logRecord{message: string(data), level: level})
}

func captureDefaultLog(t *testing.T) *captureWriter {
t.Helper()
captured := &captureWriter{}
gologger.DefaultLogger.SetMaxLevel(levels.LevelInfo)
gologger.DefaultLogger.SetWriter(captured)
t.Cleanup(func() {
gologger.DefaultLogger.SetMaxLevel(levels.LevelInfo)
gologger.DefaultLogger.SetWriter(writer.NewCLI())
})
return captured
}

func skipMessage(records []logRecord) string {
for _, rec := range records {
if rec.level == levels.LevelInfo && strings.Contains(rec.message, "Skipping provider") {
return rec.message
}
}
return ""
}

func writeKubeconfig(t *testing.T) string {
t.Helper()
kubeconfig := filepath.Join(t.TempDir(), "config")
require.NoError(t, os.WriteFile(kubeconfig, []byte(`apiVersion: v1
kind: Config
Expand All @@ -23,26 +62,74 @@ contexts:
cluster: test
current-context: test
`), 0o600))
return kubeconfig
}

func TestNewInventorySkipsProvidersWithoutCredentials(t *testing.T) {
kubeconfig := writeKubeconfig(t)
r := &Runner{options: &Options{AutoDiscovery: true}}
logs := captureDefaultLog(t)

inv, err := r.newInventory(schema.Options{
{"provider": "kubernetes", "kubeconfig_file": filepath.Join(t.TempDir(), "missing")},
{"provider": "kubernetes", "kubeconfig_file": kubeconfig},
})
require.NoError(t, err)
require.Len(t, inv.Providers, 1)
skip := skipMessage(logs.records)
require.Contains(t, skip, "could not create provider kubernetes")

logs.records = nil
_, err = r.newInventory(schema.Options{
{"provider": "kubernetes", "kubeconfig_file": filepath.Join(t.TempDir(), "missing")},
})
require.EqualError(t, err, "no provider credentials found in the environment")
require.ErrorContains(t, err, "no provider could be initialized")
require.ErrorContains(t, err, "could not create provider kubernetes")
require.Empty(t, skipMessage(logs.records))
}

func TestNewInventoryWithoutMatchingProviders(t *testing.T) {
r := &Runner{options: &Options{AutoDiscovery: true}}

_, err := r.newInventory(schema.Options{})
require.ErrorContains(t, err, "no auto-discovery provider matches the -p/-id filters")
}

func TestNewInventoryFailsFastWithoutAutoDiscovery(t *testing.T) {
r := &Runner{options: &Options{}}

_, err := r.newInventory(schema.Options{
{"provider": "kubernetes", "kubeconfig_file": filepath.Join(t.TempDir(), "missing")},
{"provider": "kubernetes", "kubeconfig_file": writeKubeconfig(t)},
})
require.Error(t, err)
require.ErrorContains(t, err, "could not create provider kubernetes")
}

func TestAutoDiscoveryKubernetesUsesDefaultKubeconfig(t *testing.T) {
kubeconfig := filepath.Join(t.TempDir(), "config")
require.NoError(t, os.WriteFile(kubeconfig, []byte(`apiVersion: v1
kind: Config
clusters:
- name: test
cluster:
server: https://k8s.example.test:6443
contexts:
- name: test
context:
cluster: test
current-context: test
`), 0o600))
t.Setenv("KUBERNETES_SERVICE_HOST", "")
t.Setenv("KUBECONFIG", kubeconfig)

var kubernetes schema.Options
for _, block := range autoDiscoveryConfig() {
if block["provider"] == "kubernetes" {
kubernetes = append(kubernetes, block)
}
}
r := &Runner{options: &Options{AutoDiscovery: true}}
inv, err := r.newInventory(kubernetes)
require.NoError(t, err)
require.Len(t, inv.Providers, 1)
}
2 changes: 1 addition & 1 deletion internal/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const banner = `
`

// version is the current version of cloudlist
const version = `1.5.0`
const version = `1.5.1`

// showBanner is used to show the banner to the user
func showBanner() {
Expand Down
4 changes: 3 additions & 1 deletion internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ func ParseOptions() *Options {
}
}

checkAndCreateProviderConfigFile(options)
if !options.AutoDiscovery {
checkAndCreateProviderConfigFile(options)
}
return options
}

Expand Down
13 changes: 13 additions & 0 deletions internal/runner/runner_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package runner

import (
"path/filepath"
"testing"

"github.com/projectdiscovery/cloudlist/pkg/schema"
"github.com/stretchr/testify/require"
)

func TestSanitizePrivateIPs(t *testing.T) {
Expand Down Expand Up @@ -56,3 +58,14 @@ func TestSanitizePrivateIPsOnMisclassifiedFields(t *testing.T) {
t.Fatalf("expected public addresses to remain when exclusion enabled")
}
}

func TestNewWithAutoDiscoveryIgnoresProviderConfig(t *testing.T) {
r, err := New(&Options{AutoDiscovery: true, ProviderConfig: filepath.Join(t.TempDir(), "missing.yaml")})
require.NoError(t, err)

var providers []string
for _, block := range r.config {
providers = append(providers, block["provider"])
}
require.Equal(t, autoDiscoveryProviders, providers)
}
Loading
Loading