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
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**
!package.json
!pnpm-lock.yaml
!pnpm-workspace.yaml
!.npmrc
!packages/
!packages/**
!configs/
!configs/**
**/node_modules
**/dist
**/.env
**/.env.*
**/*.private.*
**/.security-generated.json
**/master.key
**/credentials*.enc
**/.DS_Store
**/*.key
**/*.pem
77 changes: 48 additions & 29 deletions .github/workflows/api-server-security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
paths:
- 'packages/api-server/**'
- 'packages/types/**'
- 'etl/**'
- '.dockerignore'
- 'ops/container-security/**'
- 'packages/pipeline/**'
- 'packages/prefetch/**'
- 'apps/web/lib/server/**'
Expand All @@ -24,21 +27,11 @@ on:
- 'apps/web/lib/content-security.ts'
- 'apps/web/next.config.mjs'
- 'apps/web/vercel.json'
- 'etl/config/database.yml'
- 'etl/config/environments/production.rb'
- 'apps/web/proxy.ts'
- 'packages/site-shell/src/safe-json.ts'
- 'packages/sync-github-data/**'
- 'scripts/load-collection.mjs'
- 'scripts/lib/**'
- 'etl/lib/sample_importer.rb'
- 'etl/lib/importer.rb'
- 'etl/db/seeds.rb'
- 'etl/db/seed.sql'
- 'etl/lib/tasks/import.rake'
- 'etl/test/sample_importer_test.rb'
- 'etl/test/seeds_test.rb'
- 'etl/test/archive_transport_test.rb'
- 'pnpm-lock.yaml'
- '.github/workflows/api-server-security.yml'
- '.github/workflows/sync-collection-configs.yml'
Expand All @@ -50,6 +43,9 @@ on:
paths:
- 'packages/api-server/**'
- 'packages/types/**'
- 'etl/**'
- '.dockerignore'
- 'ops/container-security/**'
- 'packages/pipeline/**'
- 'packages/prefetch/**'
- 'apps/web/lib/server/**'
Expand All @@ -69,21 +65,11 @@ on:
- 'apps/web/lib/content-security.ts'
- 'apps/web/next.config.mjs'
- 'apps/web/vercel.json'
- 'etl/config/database.yml'
- 'etl/config/environments/production.rb'
- 'apps/web/proxy.ts'
- 'packages/site-shell/src/safe-json.ts'
- 'packages/sync-github-data/**'
- 'scripts/load-collection.mjs'
- 'scripts/lib/**'
- 'etl/lib/sample_importer.rb'
- 'etl/lib/importer.rb'
- 'etl/db/seeds.rb'
- 'etl/db/seed.sql'
- 'etl/lib/tasks/import.rake'
- 'etl/test/sample_importer_test.rb'
- 'etl/test/seeds_test.rb'
- 'etl/test/archive_transport_test.rb'
- 'pnpm-lock.yaml'
- '.github/workflows/api-server-security.yml'
- '.github/workflows/sync-collection-configs.yml'
Expand Down Expand Up @@ -125,17 +111,50 @@ jobs:
npm audit --prefix ops/collection-sync --omit=dev --audit-level=high
cd ops/collection-sync
node -e "if (typeof require('@tidbcloud/serverless').connect !== 'function') process.exit(1)"
- uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1
with:
ruby-version: '3.3'
- run: ruby etl/test/sample_importer_test.rb
- run: ruby etl/test/seeds_test.rb
- run: ruby etl/test/archive_transport_test.rb
- name: Verify ETL transport defaults
run: |
ruby -rerb -ryaml -rjson -ropenssl -e 'config = YAML.safe_load(ERB.new(File.read("etl/config/database.yml")).result, permitted_classes: [Symbol], aliases: true); abort "TLS not enforced" unless config["production"]["ssl_mode"] == :verify_identity'
- name: Verify TiDB execution and database grants
env:
NODE_OPTIONS: --experimental-vm-modules
working-directory: packages/api-server
run: pnpm exec jest --maxWorkers=12 --runTestsByPath __tests__/core/executor/query-executor/TiDBPlaygroundQueryExecutor.ts __tests__/worker/queue-worker.ts __tests__/core/email-rekey.ts __tests__/core/app-startup.ts __tests__/core/public-abuse.ts __tests__/core/account-registration.ts

containers:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Install native Ruby build prerequisites
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends default-libmysqlclient-dev pkg-config
- uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1
with:
ruby-version: '3.4.12'
bundler: '4.0.23'
bundler-cache: true
working-directory: etl
- name: Audit locked Ruby dependencies
working-directory: etl
run: |
gem install bundler-audit -v 0.9.3 --no-document
bundler-audit check --update
- name: Verify Ruby security behavior and transport defaults
working-directory: etl
run: |
bundle exec ruby -e 'ARGV.each { |file| require_relative file }' ./test/sample_importer_test.rb ./test/seeds_test.rb ./test/archive_transport_test.rb ./test/worker_heartbeat_test.rb
ruby -rerb -ryaml -rjson -ropenssl -e 'config = YAML.safe_load(ERB.new(File.read("config/database.yml")).result, permitted_classes: [Symbol], aliases: true); abort "TLS not enforced" unless config["production"]["ssl_mode"] == :verify_identity'
- name: Build production images
run: |
docker build -f packages/api-server/Dockerfile -t ossinsight-api-security:test .
docker build -f etl/Dockerfile -t ossinsight-etl-security:test etl
- name: Verify read-only containers, native SQLite, verified TLS and real TiDB ingestion
run: python3 ops/container-security/check.py
- name: Scan runtime images for fixable high and critical vulnerabilities
env:
TRIVY_CACHE_DIR: ${{ runner.temp }}/trivy-cache
run: |
curl --fail --location --retry 3 https://github.com/aquasecurity/trivy/releases/download/v0.76.1/trivy_0.76.1_Linux-64bit.tar.gz --output "$RUNNER_TEMP/trivy.tar.gz"
echo "c7cbe3137fb8a48a17574bede3dd6beb16742d1e9772929940fc90082c39d9c0 $RUNNER_TEMP/trivy.tar.gz" | sha256sum --check --status
tar -xzf "$RUNNER_TEMP/trivy.tar.gz" -C "$RUNNER_TEMP" trivy
for image in ossinsight-api-security:test ossinsight-etl-security:test; do
"$RUNNER_TEMP/trivy" image --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 --timeout 5m "$image"
done
22 changes: 16 additions & 6 deletions etl/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
.DS_Store
.bin
.git
.gitignore
.bundleignore
.DS_Store
.bundle
.byebug_history
.rspec
tmp
log
cache
dumping*
test
config/deploy
config/master.key
config/credentials*.enc
config/credentials
public/packs
public/packs-test
node_modules
vendor/bundle
yarn-error.log
coverage/
.env.local
.env
coverage
.env
.env.*
*.private.*
**/*.key
**/*.pem
**/.env
**/.env.*
**/credentials*.enc
2 changes: 1 addition & 1 deletion etl/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.7.0
3.4.12
64 changes: 21 additions & 43 deletions etl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
FROM ruby:2.7.2-alpine

ENV BUNDLER_VERSION=2.2.3

RUN apk update && apk upgrade && apk add python3

RUN apk add --update --no-cache \
binutils-gold \
build-base \
curl \
file \
g++ \
gcc \
git \
less \
libstdc++ \
libffi-dev \
libc-dev \
linux-headers \
libxml2-dev \
libxslt-dev \
libgcrypt-dev \
make \
netcat-openbsd \
nodejs \
openssl \
pkgconfig \
tzdata \
mysql-client \
mysql-dev \
yarn \
&& rm -rf /var/cache/apk/*

RUN gem install bundler -v 2.2.3

ARG RUBY_IMAGE=ruby:3.4.12-slim-bookworm@sha256:a0636a941ef86063f17b343f6c96f271f8eeedd76febf035bb6d57bc5024682b
FROM ${RUBY_IMAGE} AS builder
RUN apt-get update && apt-get install -y --no-install-recommends build-essential default-libmysqlclient-dev pkg-config git ca-certificates && rm -rf /var/lib/apt/lists/*
RUN gem install bundler -v 4.0.23 --no-document
ENV BUNDLE_DEPLOYMENT=1 BUNDLE_FROZEN=1 BUNDLE_PATH=/bundle BUNDLE_WITHOUT=development:test
WORKDIR /app

COPY Gemfile Gemfile.lock ./
COPY start.sh ./

RUN bundle config build.nokogiri --use-system-libraries

RUN bundle check || bundle install --no-cache && rm -rf /usr/local/bundle/cache

COPY . ./
RUN bundle _4.0.23_ install --jobs 2 --retry 3 && rm -rf /bundle/ruby/*/cache

FROM ${RUBY_IMAGE} AS runtime
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends libmariadb3 mariadb-client ca-certificates tzdata && rm -rf /var/lib/apt/lists/* \
&& groupadd --gid 10001 etl && useradd --uid 10001 --gid etl --no-create-home --shell /usr/sbin/nologin etl
RUN gem install bundler -v 4.0.23 --no-document
ENV RAILS_ENV=production RAILS_LOG_TO_STDOUT=1 BUNDLE_DEPLOYMENT=1 BUNDLE_FROZEN=1 BUNDLE_PATH=/bundle BUNDLE_WITHOUT=development:test \
BOOTSNAP_CACHE_DIR=/tmp/bootsnap CACHE_DIR=/tmp/gharchives DUMP_DIR=/tmp/ossinsight-dumps \
DB_SSL_CA=/etc/ssl/certs/ca-certificates.crt SAMPLE_MYSQL_CLIENT_FLAVOR=mariadb ETL_HEARTBEAT_PATH=/tmp/ossinsight-etl.heartbeat
WORKDIR /app
COPY --from=builder /bundle /bundle
COPY . ./
RUN chmod -R a+rX,go-w /app /bundle && chmod 0555 start.sh
USER 10001:10001
HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=3 CMD ["ruby", "bin/healthcheck"]
CMD ["./start.sh"]
25 changes: 11 additions & 14 deletions etl/Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
source 'https://rubygems.org'
ruby '>= 3.4.12', '< 3.5'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.4', '>= 6.1.4.1'
gem 'rails', '~> 8.1.4', '>= 8.1.4.1'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.5.4'
gem 'mysql2', '~> 0.5.7'
# Use Puma as the app server
gem 'puma', '~> 5.0'
gem 'puma', '~> 8.0', '>= 8.0.2'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
Expand All @@ -28,7 +29,7 @@ gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'byebug', platforms: [:mri, :windows]
end

group :development do
Expand All @@ -42,32 +43,28 @@ group :development do
end

group :test do
gem 'minitest-mock'
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
# Selenium includes its own driver manager.
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'tzinfo-data', platforms: [:windows, :jruby]

gem "yajl-ruby", "~> 1.4"

gem "activerecord-tidb-adapter", "~> 6.1"

gem "dotenv-rails", "~> 2.7", require: 'dotenv/rails-now'
gem "dotenv-rails", "~> 3.2", require: 'dotenv/load'

gem "pry-rails", "~> 0.3.9"

gem "retryable", "~> 3.0"

gem "annotate", "~> 3.1"

gem "csv", "~> 3.2"

gem "mdtable", "~> 0.0.2"

gem "twitter", "~> 7.0"
gem "twitter", "~> 8.3"

gem "htmlcsstoimage-api", "~> 0.1.2"
gem "htmlcsstoimage-api", "~> 0.3"
Loading
Loading