Skip to content

Commit 1b727dd

Browse files
committed
Add go code
1 parent ea1c71d commit 1b727dd

15 files changed

+925
-0
lines changed

.github/workflows/codeql-analysis.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [main]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [main]
20+
schedule:
21+
- cron: "26 22 * * 5"
22+
23+
jobs:
24+
codeql-analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
language: ["go"]
32+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33+
# Learn more:
34+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v2
39+
40+
# Initializes the CodeQL tools for scanning.
41+
- name: Initialize CodeQL
42+
uses: github/codeql-action/init@v1
43+
with:
44+
languages: ${{ matrix.language }}
45+
# If you wish to specify custom queries, you can do so here or in a config file.
46+
# By default, queries listed here will override any specified in a config file.
47+
# Prefix the list here with "+" to use these queries and those in the config file.
48+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
49+
50+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
51+
# If this step fails, then you should remove it and run the build manually (see below)
52+
- name: Autobuild
53+
uses: github/codeql-action/autobuild@v1
54+
55+
# ℹ️ Command-line programs to run using the OS shell.
56+
# 📚 https://git.io/JvXDl
57+
58+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
59+
# and modify them (or add more) to build your code if your project
60+
# uses a compiled language
61+
62+
#- run: |
63+
# make bootstrap
64+
# make release
65+
66+
- name: Perform CodeQL Analysis
67+
uses: github/codeql-action/analyze@v1

.github/workflows/deploy-to-bcr.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy to BCR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, closed]
6+
branches:
7+
- master
8+
9+
jobs:
10+
deploy-to-bcr:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Turnstyle
16+
uses: softprops/turnstyle@v1
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Deploy to Balena
21+
uses: balena-io/deploy-to-balena-action@master
22+
id: build
23+
with:
24+
balena_token: ${{ secrets.BALENA_TOKEN }}
25+
fleet: maggie0002/balena-data-extractor
26+
27+
- name: Log release ID built
28+
run: echo "Built release ID ${{ steps.build.outputs.release_id }}"

.github/workflows/deploy-to-ghcr.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Deploy to GHCR
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: maggie0002/balena-data-extractor
11+
12+
jobs:
13+
deploy-to-gcr:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v2
22+
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v1
25+
26+
- name: Set up Docker Buildx
27+
id: buildx
28+
uses: docker/setup-buildx-action@v1
29+
30+
- name: Available platforms
31+
run: echo ${{ steps.buildx.outputs.platforms }}
32+
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@v1
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v3
43+
with:
44+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+
flavor: |
46+
latest=true
47+
tags: |
48+
type=semver,pattern={{version}}
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v2
52+
with:
53+
context: .
54+
file: ./Dockerfile
55+
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
balena-data-extractor
3+
.vscode
4+
cmds.yml

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM golang:1.18.2 as builder
2+
3+
ENV CGO_ENABLED=0
4+
5+
WORKDIR /build
6+
7+
COPY . .
8+
9+
RUN go build -ldflags '-w -s'
10+
11+
12+
FROM alpine:3.16
13+
14+
ENV PRIVATEBIN_URL=https://privatebin.net
15+
16+
WORKDIR /app
17+
18+
# COPY cmds.yaml cmds.yaml
19+
20+
COPY --from=builder /build/balena-data-extractor .
21+
22+
ENTRYPOINT ["./balena-data-extractor"]

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Balena Data Extractor
2+
3+
[![balena deploy button](https://www.balena.io/deploy.svg)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/maggie0002/balena-data-extractor)
4+
5+
This is an experimental project for extracting various forms of data (such as device information or logs) from Balena devices and uploading it to [PrivateBin](https://privatebin.info/directory/); a secure online version of PasteBin.
6+
7+
All of the extracted content is encrypted on the device before being uploaded to PrivateBin meaning PrivateBin cannot see any of the stored content. You can retrieve data by using the URL returned by this container, which includes your key for decrypting the content. For added security, you can apply a password required when accessing the content on the PrivateBin website.
8+
9+
As an added bonus and for even greater security and privacy, you can run your own instance of the open source [PrivateBin](https://privatebin.info/directory/) project on your own server and then pass the URL of your server to this container via an environment variable or to the executable (see below).
10+
11+
12+
# Basic Usage:
13+
14+
Run the container and the default mode will extract the following content and create an individual URL for each:
15+
16+
```
17+
Device Info (via the Balena Supervisor)
18+
Environment Variables (API_KEY variables are filtered out)
19+
JournalCtl Logs
20+
A List of Network Interfaces
21+
```
22+
23+
## With the Docker Compose file:
24+
25+
Add the `balena-data-extractor` section of docker-compose.yml file in this repository to your own docker-compose file.
26+
27+
## With a `run` command on a device:
28+
29+
`balena run bcr.io/maggie0002/balena-data-extractor`
30+
31+
# Advanced Usage
32+
33+
You can change the default PrivateBin instance used by modifying the PRIVATEBIN_URL in the Docker Compose file or by [passing the env variable](https://docs.docker.com/engine/reference/run/#env-environment-variables) to the `balena run` command.
34+
35+
You can use a cmds.yaml file to generate your own commands to execute and pass to PrivateBin (see cmds.example.yaml file) by passing `-data yaml` and copying a cmds.yml file in to the container with the Dockerfile.
36+
37+
You can also set additional options by passing them in the Docker Compose command field or by putting them at the end of your `balena run` command:
38+
39+
-burn
40+
Burn all data after being read once
41+
-expire string
42+
Delete all data after specified time. Options are: 'hour', 'day', 'week' or 'month' (default "day")
43+
-data string
44+
Choose which data to export. Options are: 'all', 'deviceinfo', 'envvars', 'journalctl', 'networkinterfaces', 'yaml') (default "all")
45+
-password string
46+
Set a password for accessing the uploaded content
47+
-url string
48+
Override the default data host with the passed URL
49+
-help
50+
Show this content
51+
52+
* Only the last 10000 lines of the JournalCtl logs are returned otherwise the browser struggles to decrypt it.

balena.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Balena Data Extractor
2+
description: >-
3+
A container for extracting data from Balena devices and uploading to a secure website (PrivateBin).
4+
joinable: false
5+
type: sw.block
6+
assets:
7+
repository:
8+
type: blob.asset
9+
data:
10+
url: "https://github.com/maggie0002/balena-data-extractor"
11+
logo:
12+
type: blob.asset
13+
data:
14+
url: "https://raw.githubusercontent.com/maggie0002/balena-apps-logo/main/logo.png"
15+
data:
16+
defaultDeviceType: raspberrypi4-64
17+
supportedDeviceTypes:
18+
- raspberry-pi
19+
- raspberry-pi2
20+
- raspberrypi3
21+
- raspberrypi3-64
22+
- raspberrypi4-64
23+
- fincm3
24+
- raspberrypi400-64
25+
- intel-nuc
26+
- genericx86-64-ext

cmds.example.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
api:
2+
name: GitHub API
3+
url: https://api.github.com
4+
key: your-api-key-or-remove-this-line
5+
file:
6+
name: OS Release Info
7+
path: /etc/os-release
8+
shell:
9+
name: Contents of the programme folder
10+
cmd: ls -lah

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2.1"
2+
3+
services:
4+
balena-data-extractor:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
environment:
9+
PRIVATEBIN_URL: https://privatebin.net
10+
restart: no
11+
labels:
12+
io.balena.features.supervisor-api: 1
13+
# command: -data all

0 commit comments

Comments
 (0)