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

⭐️ atlassian provider #2253

Merged
merged 90 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
d4ad8b4
⭐️ atlassian provider
mariuskimmina Oct 2, 2023
f98be0d
wip
mariuskimmina Oct 3, 2023
6869222
fix spelling
mariuskimmina Oct 3, 2023
137fd6a
wip
mariuskimmina Oct 3, 2023
7627896
wip
mariuskimmina Oct 4, 2023
9cce482
connection and receiving organizations works
mariuskimmina Oct 4, 2023
8cda130
adding basic jira and confluence
mariuskimmina Oct 4, 2023
2b1e9f7
wip getting users from jira
mariuskimmina Oct 4, 2023
8902a83
receving users from jira works
mariuskimmina Oct 4, 2023
f74a28e
fix spelling
mariuskimmina Oct 4, 2023
d9960ef
add confluence to spelling
mariuskimmina Oct 4, 2023
a8594b2
working on confluence
mariuskimmina Oct 4, 2023
dd53151
add account type for filtering
mariuskimmina Oct 4, 2023
05c1766
add groups to jira users
mariuskimmina Oct 4, 2023
a97fc07
getting users from confluence works
mariuskimmina Oct 5, 2023
d173c7a
add user type to filter out bots
mariuskimmina Oct 5, 2023
beeca19
add organization policies
mariuskimmina Oct 5, 2023
08facf6
add domains
mariuskimmina Oct 5, 2023
d286d99
events
mariuskimmina Oct 5, 2023
65d84f2
v9 all the things
mariuskimmina Oct 6, 2023
a47afdc
fix policy id
mariuskimmina Oct 6, 2023
743ec20
jira projects
mariuskimmina Oct 9, 2023
da6b817
fix jira projects
mariuskimmina Oct 9, 2023
bf996a9
add more field to jira project
mariuskimmina Oct 9, 2023
db7bf6b
make scan work
mariuskimmina Oct 9, 2023
b2ab7c6
fix platform id
mariuskimmina Oct 9, 2023
592c3ac
fix groups and add applicationRoles
mariuskimmina Oct 10, 2023
0097491
add platform
mariuskimmina Oct 10, 2023
1086cc1
groups and serverinfo
mariuskimmina Oct 11, 2023
8143293
fix serverinfo
mariuskimmina Oct 11, 2023
4f8e6a0
fixup
mariuskimmina Oct 11, 2023
8589585
comments
mariuskimmina Oct 11, 2023
376ab89
atlassian admin users
mariuskimmina Oct 11, 2023
5d321b7
last active
mariuskimmina Oct 11, 2023
ff9bdfe
last active
mariuskimmina Oct 11, 2023
f3648b4
add ids to last active
mariuskimmina Oct 12, 2023
d0414eb
add issues
mariuskimmina Oct 12, 2023
05a8404
add fields to issue
mariuskimmina Oct 12, 2023
635df02
clean up
mariuskimmina Oct 12, 2023
0ee78a4
fix asset name and add scim
mariuskimmina Oct 12, 2023
e10758b
scim groups
mariuskimmina Oct 12, 2023
fe063fa
managed users
mariuskimmina Oct 13, 2023
fe2f1b6
better naming + error handling
mariuskimmina Oct 13, 2023
2fe64af
remove hardcoded host and user
mariuskimmina Oct 13, 2023
beee2fe
split
mariuskimmina Oct 13, 2023
46f6189
fixes
mariuskimmina Oct 13, 2023
48ef347
fixes
mariuskimmina Oct 13, 2023
3477401
fixes
mariuskimmina Oct 13, 2023
458736a
add jira
mariuskimmina Oct 13, 2023
591561a
add flags
mariuskimmina Oct 13, 2023
1629b86
fixes
mariuskimmina Oct 13, 2023
ac26138
clean up
mariuskimmina Oct 13, 2023
2d41302
use subcommands
mariuskimmina Oct 16, 2023
a4d3a27
better errors
mariuskimmina Oct 16, 2023
1838aef
scim and clean up
mariuskimmina Oct 16, 2023
cb02d40
directory id argument
mariuskimmina Oct 16, 2023
155fdcf
clean up
mariuskimmina Oct 16, 2023
6a1f974
add more fields to scim user
mariuskimmina Oct 16, 2023
d7a3e46
remove unused type
mariuskimmina Oct 16, 2023
75c69e9
remove response checking
mariuskimmina Oct 16, 2023
ca2a314
return err instead of log.fatal
mariuskimmina Oct 16, 2023
5d0f026
clean up
mariuskimmina Oct 16, 2023
1e62146
more fields
mariuskimmina Oct 16, 2023
878a3a0
fix formatting
mariuskimmina Oct 16, 2023
7accffe
add name to scim group
mariuskimmina Oct 16, 2023
a1c3842
fix platformid
mariuskimmina Oct 16, 2023
52e873c
fixes
mariuskimmina Oct 16, 2023
e3df517
fix platform id
mariuskimmina Oct 16, 2023
d80425d
add directoryid to scim platformid
mariuskimmina Oct 16, 2023
20c0ee6
working on discovery
mariuskimmina Oct 16, 2023
2b9e994
return err instead of log.fatal
mariuskimmina Oct 16, 2023
41d73b0
remove discovery and make user provide org id
mariuskimmina Oct 16, 2023
c80c9bd
clean up
mariuskimmina Oct 16, 2023
347ef01
add docs
mariuskimmina Oct 16, 2023
29748d7
add docs
mariuskimmina Oct 16, 2023
4969478
better defaults
mariuskimmina Oct 16, 2023
bd76e1c
fix makefile
mariuskimmina Oct 16, 2023
6e556bf
fix provider build
imilchev Oct 16, 2023
3b70d29
fix spelling
mariuskimmina Oct 16, 2023
1f9dd3f
add license headers
mariuskimmina Oct 16, 2023
fd073a9
add flags
mariuskimmina Oct 16, 2023
972f0c1
fix
mariuskimmina Oct 16, 2023
44e0c67
prevent conversion panics
mariuskimmina Oct 16, 2023
a95b354
fix token flag names
mariuskimmina Oct 16, 2023
697dfc1
fix error messages
mariuskimmina Oct 16, 2023
76f94cf
fix default connection types
mariuskimmina Oct 16, 2023
1456fa0
fix platform name
mariuskimmina Oct 16, 2023
8bbb3f5
fix title too human readable name
mariuskimmina Oct 16, 2023
8aae86c
fix scim name
mariuskimmina Oct 16, 2023
da1f75b
change host to name
mariuskimmina Oct 16, 2023
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
4 changes: 4 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aks
atlassian
Auths
autoaccept
autoscaler
Expand All @@ -8,6 +9,7 @@ cavium
cdn
certificatechains
cmek
confluence
cryptokey
customresources
datapath
Expand All @@ -25,6 +27,7 @@ iap
ilb
ingresstls
iotedge
jira
linux
loggingservice
managedzone
Expand All @@ -44,6 +47,7 @@ querypack
resourcegroup
Sas
SAMEORIGIN
scim
serviceprincipals
Snat
spdx
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ providers/build: \
providers/build/k8s \
providers/build/azure \
providers/build/ms365 \
providers/build/aws
providers/build/aws \
providers/build/atlassian

.PHONY: providers/install
# Note we need \ to escape the target line into multiple lines
Expand All @@ -210,6 +211,7 @@ providers/install: \
providers/install/k8s \
providers/install/azure \
providers/install/ms365 \
providers/install/atlassian \
providers/install/aws

providers/build/mock: providers/lr
Expand Down Expand Up @@ -313,6 +315,11 @@ providers/build/aws: providers/lr
providers/install/aws:
@$(call installProvider, providers/aws)

providers/build/atlassian: providers/lr
imilchev marked this conversation as resolved.
Show resolved Hide resolved
@$(call buildProvider, providers/atlassian)
providers/install/atlassian:
@$(call installProvider, providers/atlassian)

providers/build/ms365: providers/lr
@$(call buildProvider, providers/ms365)
providers/install/ms365:
Expand All @@ -339,6 +346,7 @@ providers/dist:
@$(call buildProviderDist, providers/azure)
@$(call buildProviderDist, providers/ms365)
@$(call buildProviderDist, providers/aws)
@$(call buildProviderDist, providers/atlassian)

providers/bundle:
@$(call bundleProvider, providers/network)
Expand All @@ -361,6 +369,7 @@ providers/bundle:
@$(call bundleProvider, providers/azure)
@$(call bundleProvider, providers/ms365)
@$(call bundleProvider, providers/aws)
@$(call bundleProvider, providers/atlassian)

providers/test:
@$(call testProvider, providers/core)
Expand All @@ -384,6 +393,7 @@ providers/test:
@$(call testGpModProvider, providers/azure)
@$(call testGpModProvider, providers/ms365)
@$(call testGpModProvider, providers/aws)
@$(call testGpModProvider, providers/atlassian)

lr/test:
go test ./resources/lr/...
Expand Down
63 changes: 63 additions & 0 deletions providers/atlassian/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package config

import (
"go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v9/providers/atlassian/provider"
)

var Config = plugin.Provider{
Name: "atlassian",
ID: "go.mondoo.com/cnquery/providers/atlassian",
Version: "9.0.0",
ConnectionTypes: []string{
provider.DefaultConnectionType,
"jira",
"admin",
"confluence",
"scim",
},
Connectors: []plugin.Connector{
{
Name: "atlassian",
Use: "atlassian",
Short: "atlassian",
MaxArgs: 2,
Discovery: []string{},
Flags: []plugin.Flag{
{
Long: "admin-token",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian admin api token (used for atlassian admin).",
},
{
Long: "host",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian hostname (e.g. https://example.atlassian.net).",
},
{
Long: "user",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian user name (e.g. [email protected]).",
},
{
Long: "user-token",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian user api token (used for jira / confluence).",
},
{
Long: "scim-token",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian scim api token (used for scim).",
},
},
},
},
}
81 changes: 81 additions & 0 deletions providers/atlassian/connection/admin/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package admin

import (
"errors"
"os"

"github.com/ctreminiom/go-atlassian/admin"
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared"
)

const (
Admin shared.ConnectionType = "admin"
)

type AdminConnection struct {
id uint32
Conf *inventory.Config
asset *inventory.Asset
client *admin.Client
name string
}

func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) {
adminToken := conf.Options["admin-token"]
if adminToken == "" {
adminToken = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
}
if adminToken == "" {
return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_ADMIN_TOKEN env or via the --admin-token flag")
}

client, err := admin.New(nil)
if err != nil {
return nil, err
}

client.Auth.SetBearerToken(adminToken)
client.Auth.SetUserAgent("curl/7.54.0")

conn := &AdminConnection{
Conf: conf,
id: id,
asset: asset,
client: client,
name: "admin.atlassian.com",
}

return conn, nil
}

func (c *AdminConnection) Name() string {
return c.name
}

func (c *AdminConnection) ID() uint32 {
return c.id
}

func (c *AdminConnection) Asset() *inventory.Asset {
return c.asset
}

func (c *AdminConnection) Client() *admin.Client {
return c.client
}

func (c *AdminConnection) Type() shared.ConnectionType {
return Admin
}

func (c *AdminConnection) ConnectionType() string {
return "admin"
}

func (c *AdminConnection) Config() *inventory.Config {
return c.Conf
}
33 changes: 33 additions & 0 deletions providers/atlassian/connection/admin/platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package admin

import (
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
)

func (a *AdminConnection) PlatformInfo() *inventory.Platform {
return GetPlatformForObject("atlassian-admin")
}

func GetPlatformForObject(platformName string) *inventory.Platform {
if platformName != "atlassian-admin" && platformName != "" {
return &inventory.Platform{
Name: platformName,
Title: "Atlassian Admin",
Kind: "api",
Runtime: "atlassian",
}
}
return &inventory.Platform{
Name: "atlassian-admin",
Title: "Atlassian Admin",
Kind: "api",
Runtime: "atlassian",
}
}

func (a *AdminConnection) PlatformID() string {
return "//platformid.api.mondoo.app/runtime/atlassian/admin"
}
97 changes: 97 additions & 0 deletions providers/atlassian/connection/confluence/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package confluence

import (
"errors"
"os"

"github.com/ctreminiom/go-atlassian/confluence"
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared"
)

const (
Confluence shared.ConnectionType = "confluece"
)

type ConfluenceConnection struct {
id uint32
Conf *inventory.Config
asset *inventory.Asset
client *confluence.Client
name string
}

func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ConfluenceConnection, error) {
host := conf.Options["host"]
if host == "" {
host = os.Getenv("ATLASSIAN_HOST")
}
if host == "" {
return nil, errors.New("you need to provide atlassian hostname via ATLASSIAN_HOST env or via --host flag")
}

user := conf.Options["user"]
if user == "" {
user = os.Getenv("ATLASSIAN_USER")
}
if user == "" {
return nil, errors.New("you need to provide atlassian username via ATLASSIAN_USER env or via --user flag")
}

token := conf.Options["user-token"]
if token == "" {
token = os.Getenv("ATLASSIAN_USER_TOKEN")
}
if token == "" {
return nil, errors.New("you need to provide atlassian user token via ATLASSIAN_USER_TOKEN env or via --user-token flag")
}

client, err := confluence.New(nil, host)
if err != nil {
return nil, err
}

client.Auth.SetBasicAuth(user, token)
client.Auth.SetUserAgent("curl/7.54.0")

conn := &ConfluenceConnection{
Conf: conf,
id: id,
asset: asset,
client: client,
name: host,
}

return conn, nil
}

func (c *ConfluenceConnection) Name() string {
return c.name
}

func (c *ConfluenceConnection) ID() uint32 {
return c.id
}

func (c *ConfluenceConnection) Asset() *inventory.Asset {
return c.asset
}

func (c *ConfluenceConnection) Client() *confluence.Client {
return c.client
}

func (c *ConfluenceConnection) Type() shared.ConnectionType {
return Confluence
}

func (c *ConfluenceConnection) ConnectionType() string {
return "confluence"
}

func (c *ConfluenceConnection) Config() *inventory.Config {
return c.Conf
}
37 changes: 37 additions & 0 deletions providers/atlassian/connection/confluence/platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package confluence

import (
"strings"

"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
)

func (a *ConfluenceConnection) PlatformInfo() *inventory.Platform {
return GetPlatformForObject("atlassian-confluence")
}

func GetPlatformForObject(platformName string) *inventory.Platform {
if platformName != "atlassian-confluence" && platformName != "" {
return &inventory.Platform{
Name: platformName,
Title: "Atlassian Confluence",
Kind: "api",
Runtime: "atlassian",
}
}
return &inventory.Platform{
Name: "atlassian-confluence",
Title: "Atlassian Confluence",
Kind: "api",
Runtime: "atlassian",
}
}

func (a *ConfluenceConnection) PlatformID() string {
hostname := strings.TrimPrefix(a.name, "https://")
host := strings.Replace(hostname, ".", "-", -1)
return "//platformid.api.mondoo.app/runtime/atlassian/confluence/" + host
}
Loading
Loading