Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
ca55db7
added explicit schema to table object to avoid unintended type coerci…
shagamemnon May 1, 2018
a6464bf
Merge pull request #1 from shagamemnon/master
garrettgalow May 2, 2018
72ef1f1
update schema with additional fields
andywimmer May 23, 2018
d3c464d
added logical to read schema from remote JSON file
shagamemnon May 24, 2018
af38106
Merge pull request #4 from cloudflare/remote-schema
shagamemnon May 24, 2018
cb36b0d
Merge pull request #3 from andywimmer/DS-5963
shagamemnon May 24, 2018
ed3069c
updated version
shagamemnon May 24, 2018
fb3e3cc
🧐
shagamemnon May 24, 2018
465e148
Merge pull request #5 from cloudflare/remote-schema
shagamemnon May 24, 2018
fce4b69
Update README.md
shagamemnon May 24, 2018
65ec30d
Update README.md
shagamemnon Sep 7, 2018
8d59406
Create start.sh
shagamemnon Sep 7, 2018
b02fbc1
Update README.md
shagamemnon Sep 7, 2018
6c81fdd
Update README.md
shagamemnon Sep 7, 2018
15e0a0b
Update README.md
shagamemnon Sep 7, 2018
d9d1b3e
Create cloudshell.txt
shagamemnon Sep 7, 2018
7a3a0e1
Update README.md
shagamemnon Sep 7, 2018
5589f00
Update README.md
shagamemnon Sep 7, 2018
c3a8268
Update and rename cloudshell.txt to cloudshell.md
shagamemnon Sep 7, 2018
fe1ba07
Update cloudshell.md
shagamemnon Sep 7, 2018
4604d66
Update cloudshell.md
shagamemnon Sep 7, 2018
32a6d3d
Update README.md
shagamemnon Sep 7, 2018
96d87f9
Temporarily removed GCP deploy button
shagamemnon Oct 17, 2018
9e4128d
Update README.md
shagamemnon Oct 17, 2018
1d29eb0
Update start.sh
shagamemnon Oct 29, 2018
de8804d
Update start.sh
shagamemnon Oct 29, 2018
c10f9a5
Update README.md
shagamemnon Oct 29, 2018
c57b7ac
Update start.sh
shagamemnon Dec 14, 2018
985ac59
Update start.sh
shagamemnon Dec 14, 2018
25ae07c
Rewrote to conform to Node 8 runtime
shagamemnon Dec 14, 2018
57e34dc
Update start.sh
shagamemnon Dec 14, 2018
76c4afc
Update handler for new node8 runtime.
sourcec0de Jan 1, 2019
1107c1d
Merge pull request #13 from sourcec0de/patch-1
shagamemnon Jan 17, 2019
c232831
Merge pull request #1 from cloudflare/master
shagamemnon Jan 22, 2019
18e5833
upgraded to bigquery 2.0 client, increased memory limits and replaced…
shagamemnon Jan 22, 2019
44b8c5e
Added autoCreate:true option to dataset and table getters and refacto…
shagamemnon Jan 22, 2019
e44a002
Merge pull request #14 from shagamemnon/node8
shagamemnon Jan 22, 2019
674d6cd
Update README.md
shagamemnon Jan 22, 2019
55d3f71
Update README.md
shagamemnon Jan 22, 2019
a94598f
Update README.md
shagamemnon Jan 22, 2019
a5ee3ab
Deleted WRITE_TRUNCATE opt to avoid accidental deletions
shagamemnon Jan 22, 2019
7082019
added function name variable
shagamemnon Mar 7, 2019
9145d79
Changed FUNCTIONS variable default
shagamemnon Mar 15, 2019
50ac9b8
patched dependency versions
shagamemnon Mar 20, 2019
ebf3f28
moved cloud functions into subdir
shagamemnon Mar 22, 2019
972abb9
Update README.md
shagamemnon Mar 22, 2019
7c38689
Update README.md
shagamemnon Mar 22, 2019
3d0be8c
Update README.md
shagamemnon Mar 22, 2019
d70e482
Update README.md
shagamemnon Mar 22, 2019
afb3fcf
consolidated gcp cloud function repositories
shagamemnon Apr 25, 2019
4eda8d2
Merge pull request #15 from cloudflare/staging
shagamemnon Apr 25, 2019
3c0866b
Update README.md
shagamemnon Apr 25, 2019
1740694
Update service.yml
shagamemnon Apr 25, 2019
58e3587
continued integration of sec-events and logpush funcs
shagamemnon Apr 29, 2019
d038197
Merge pull request #16 from cloudflare/beta
shagamemnon Apr 29, 2019
500eea6
Update README.md
shagamemnon Apr 29, 2019
a1c3f61
include bigquery instantiation
Apr 29, 2019
b6d8ee1
Merge pull request #17 from gpacuilla/master
shagamemnon Apr 29, 2019
39b1c27
bug fixes: dataset now created automatically, gcp button link works
shagamemnon May 13, 2019
0ef5b7c
Merge pull request #19 from cloudflare/auto-create-dataset
shagamemnon May 13, 2019
ac7c275
updated table row counter and static queries
shagamemnon May 15, 2019
305971d
modified permissions and iam user state
shagamemnon May 15, 2019
0febc25
merged changes from logpush deploy
shagamemnon May 15, 2019
da1b576
reduced permissions scope
shagamemnon May 15, 2019
7559bd6
correct chalk-pipe usage
LitoMore Jun 5, 2019
2ce0036
Merge pull request #21 from LitoMore/correct-chak-pipe-usage
shagamemnon Jun 5, 2019
0525c58
Update README.md
shagamemnon Jul 17, 2019
f95671f
Update README.md
shagamemnon Jul 17, 2019
615e018
Add new firewall events repeated fields
shagamemnon Aug 12, 2019
392962c
update README.md
mihaiturcu Oct 12, 2019
5b20eae
Merge pull request #1 from mihaiturcu/mihaiturcu-patch-1
mihaiturcu Oct 12, 2019
e7dbe1b
Merge pull request #23 from mihaiturcu/master
shagamemnon Oct 30, 2019
080d4ee
Update README.md
shagamemnon Nov 11, 2019
c51c82b
updated cli and scc to alpha-v3. breaking changes
shagamemnon Jan 15, 2020
f7eaeee
updated readme and removed unused files
shagamemnon Jan 15, 2020
89af0f0
fixed merge conflict
shagamemnon Jan 15, 2020
d539898
cleaned up tutorials
shagamemnon Jan 15, 2020
eb3709c
added tutorial
shagamemnon Jan 15, 2020
8b7c1c2
divided readmes into subdirs
shagamemnon Jan 15, 2020
d79427a
made node 10 compatible
shagamemnon Feb 11, 2020
638bd4b
set node version for cloud function
shagamemnon Feb 11, 2020
72e2fd0
ack for pubsub event
shagamemnon Feb 11, 2020
3342fa8
Update schema with bot score and X-Requested-With
shagamemnon Feb 21, 2020
d7582e2
Update README.md
shagamemnon Feb 28, 2020
20708eb
Added BotScoreSrc to schema
shagamemnon Mar 5, 2020
fe1ad07
Update README.md
shagamemnon Mar 9, 2020
1e62e96
upgrade to node 10
marchenko1985 Jun 2, 2020
84efbd7
Merge pull request #45 from mac2000/patch-1
shagamemnon Jun 2, 2020
cd1710d
added gcp project id module
shagamemnon Jun 2, 2020
e779deb
Merge pull request #46 from cloudflare/cloudshell-update
shagamemnon Jun 5, 2020
05d7971
Adding Spectrum schema (#44)
itsmatteomanf Jun 5, 2020
50ec525
Update README.md
shagamemnon Jun 5, 2020
b6b4354
Add support for time partitioning
igorwwwwwwwwwwwwwwwwwwww Jun 10, 2020
c3286a3
Update README.md
igorwwwwwwwwwwwwwwwwwwww Jun 10, 2020
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
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
17 changes: 17 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

node_modules
#!include:.gitignore
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
node_modules/**

# Serverless
.serverless
.env*
tmp
.coveralls.yml
logs.js
# Google
keyfile.json

# Logs
*.log

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# IDE
**/.idea

# OS
.vscode
cloudflare-gcp.code-workspace

security-events/.env.yml
security-events/node_modules
security-events/scc_key.json
security-events/.DS_Store
security-events/local.js

cli/node_modules

logpush-to-bigquery/.DS_Store
logpush-to-bigquery/node_modules
cli/dist
cli/confs
29 changes: 4 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
# GCS To Big Query Cloud Function
Google Cloud Function Code to push json files from GCS to Big Query
# Cloudflare + Google Cloud | Integrations
Integrate Cloudflare Enterprise Log Push with BigQuery and Security Command Center on Google Cloud.

### Requirements
If using the Google Cloud UI to upload then there are no local requirements.
* [Cloudflare Log Push to BigQuery](https://github.com/cloudflare/cloudflare-gcp/tree/master/logpush-to-bigquery)

[gcloud SDK](https://cloud.google.com/sdk/downloads) need to be setup to run from command line.

### Setup
Config Variables:
"DATASET" - BigQuery Dataset to write to. Will be created if necessaray.
"TABLE" - BigQuery Table to write to. Will be created if necessaray.

When deploying through gcloud or in UI, the following need to be specified:
* name: any name can be used, but if entry-point is not specified then the function name will be used.
* trigger-bucket: The Google Storage Bucket that will trigger the Cloud Function on file create. Must already exist.
* stage-bucket: Where the Cloud Function code should be kept. Should not be the same as trigger bucket in case you update the Cloud Function.
* entry-point: Should always be "jsonLoad" unless the Cloud Function name is also "jsonLoad"


### Deploying from gcloud cli
~~~
gcloud beta functions deploy <name of the cloud function>
--trigger-resource=<trigger-bucket-name> --trigger-event google.storage.object.finalize
--source=<path to gcsToBigQuery repository on your workstation> --stage-bucket=<gs://gcs-bucket>
--entry-point=jsonLoad
~~~
----
16 changes: 16 additions & 0 deletions cli/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

node_modules
7 changes: 7 additions & 0 deletions cli/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

exports = require('yargs')
.commandDir('cmds')
.demandCommand()
.help()
.argv
71 changes: 71 additions & 0 deletions cli/cloudshell-security-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Cloudflare Security Events

## Enter the Cloud Shell subdirectory for the project you want to use for the Cloudflare SCC integration
<walkthrough-project-setup></walkthrough-project-setup>

## Set Cloudshell to the project where you'd like to deploy the integration
```sh
gcloud config set project {{project-id}}
```

## Install dependencies and CLI:
Run:
```bash
sh install.sh
```

## Set Environment Variables and write deployment files
Run:
```bash
./setup setEnv
```

## Build configuration files:
Run:
```bash
./setup buildConf
```
**Tip:** If you need to edit `security-events/.env.yml` in the future, use this command to update the configuration files before redeploying.

## Enable the necessary Cloud APIs to run the Cloudflare integration
```bash
./setup enableAPIs
```

## Create Cloud Scheduler event (deployed via Pub/Sub)
```bash
./setup setSchedule
```

## Create a service account key for SCC
Run:
```bash
./setup getServiceAcctKey
```

**Tip:** This may throw some errors but if the final message succeeds, you're probably ok. Having issues? Make sure you're using the correct account:
```bash
gcloud config set account MY_GCP_ACCT_EMAIL
```

## Deploy integration
```bash
./setup deploy
```


## Done!
The configuration file, `.env.yml` can be modified here:
```sh
cd cloudflare-gcp/security-events
nano .env.yml
```

Then, to rebuild the necessary configuration files:
```sh
cd cloudflare-gcp/cli
./setup buildConf
```

<walkthrough-directive-name param-name="conclusion-trophy">
</walkthrough-directive-name>
16 changes: 16 additions & 0 deletions cli/cmds/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const child = require('child_process')

exports.command = 'account'

exports.describe = 'Get or set current Google account configuration'

exports.builder = {
dir: {
default: '.'
}
}

exports.handler = (argv) => {
if (argv.set) return child.execSync(`gcloud config set account ${argv.set}`).toString()
return child.execSync(`gcloud config get-value account --format=object`).toString()
}
72 changes: 72 additions & 0 deletions cli/cmds/buildConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { info, success, err } = require('../utils/logger')
const { baseDir, envDir, deploymentDir } = require('../utils/paths')
const vinyl = require('vinyl-fs')
const replace = require('gulp-frep')
const fs = require('fs-extra')
const del = require('del')

require('env-yaml').config({ path: envDir })

exports.command = 'buildConf'

exports.describe = 'Build or rebuild configuration files after changing .env.yml'

exports.builder = {
dir: {
default: '.'
}
}

exports.handler = (argv) => {
const patterns = [
{
pattern: /SERVICE_ACCOUNT/g,
replacement: `${process.env.SERVICE_ACCOUNT}`
},
{
pattern: /PROJECT_ID/g,
replacement: `${process.env.PROJECT_ID}`
},
{
pattern: /SOURCE_ID/g,
replacement: `${process.env.SOURCE_ID}`
},
{
pattern: /BUCKET_NAME/g,
replacement: `${process.env.BUCKET_NAME}`
},
{
pattern: /REGION/g,
replacement: `${process.env.REGION}`
},
{
pattern: /DEPLOYMENT_DIR/g,
replacement: `${deploymentDir}`
},
{
pattern: /BASE_DIR/g,
replacement: `${baseDir}`
},
{
pattern: /GCLOUD_ORG/g,
replacement: `${process.env.SOURCE_ID}`.split('/')[1]
},
{
pattern: /\*.*\s\*\s\*\s\*\s*\s\*/gi,
replacement: `*/${process.env.INTERVAL.replace('m', '')} * * * *`
}
]
setTimeout(function () {
try {
vinyl.src([`templates/*.yml`, `!templates/setEnvPrompts.yml`])
.pipe(replace(patterns))
.pipe(vinyl.dest(`confs`))
} catch (e) {
throw err(e)
} finally {
success(`\n\nService Account Key created and environment variables set. To modify this file, use \n\n$ nano ${envDir}\n\n${fs.readFileSync(envDir)}`)
info(`Project: ${process.env.PROJECT_ID}, Org: ${process.env.GCLOUD_ORG}`)
success(`Click next -->`)
}
}, 1500)
}
37 changes: 37 additions & 0 deletions cli/cmds/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const yaml = {
read: require('read-yaml')
}
const child = require('child_process')
const { info, success, err } = require('../utils/logger')
const { baseDir, deploymentDir, envDir } = require('../utils/paths')
require('env-yaml').config({ path: envDir })

exports.command = 'deploy'

exports.describe = 'Deploy Cloud Functions'

exports.builder = {
dir: {
default: '.'
}
}

exports.handler = async function deploy (argv) {
const sh = cmd => child.execSync(cmd).toString()
let file = yaml.read.sync(`${baseDir}/confs/deploy.yml`)
console.log(file.create_bucket)
try {
sh(file.create_bucket.main)
success(`Bucket created. Starting function deployment`)
} catch (e) {
info(`Bucket already created. Starting function deployment`)
} finally {
let cmdString = ''
for (let [k, v] of Object.entries(file.deploy_function)) {
cmdString += ` --${k}=${v}`
}
cmdString = 'gcloud beta functions deploy FirewallEventsToSecurityCenter' + cmdString
cmdString = cmdString.trimRight().trimLeft()
sh(cmdString)
}
}
39 changes: 39 additions & 0 deletions cli/cmds/enableAPIs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const shP = require('exec-sh').promise
const yaml = {
read: require('read-yaml')
}

exports.command = 'enableAPIs'

exports.describe = 'Enable APIs'

exports.builder = {
dir: {
default: '.'
}
}

exports.handler = async function enableAPIs () {
const { info, success, err } = require('../utils/logger')
const { baseDir } = require('../utils/paths')
let cmds = yaml.read.sync(`${baseDir}/confs/enableAPIs.yml`)
cmds = Object.values(cmds.apis)
let i = 1
const runCmds = cmds.map(async cmd => {
let out
try {
out = await shP(`${cmd}`, false)
} catch (e) {
if (e instanceof TypeError) err(e)
}
return out
})

for (const cmd of runCmds) {
await cmd
success(`${i++}/${cmds.length} .. ${cmds[i - 2]} succeeded`)
if (i === runCmds.length) {
setTimeout(() => { info('\nClick Next -->') }, 2000)
}
}
}
Loading