Skip to content

Commit

Permalink
Converting Docker image to Python 3 and fixing cascading deletes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbushkov committed Nov 26, 2019
1 parent 1869d87 commit 3440b00
Show file tree
Hide file tree
Showing 7 changed files with 824 additions and 49 deletions.
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# -p 0.0.0.0:8080:8080 \
# grrdocker/grr

FROM ubuntu:xenial
FROM mariadb:bionic

LABEL maintainer="grr-dev@googlegroups.com"

Expand All @@ -38,25 +38,25 @@ RUN apt-get update && \
git \
libffi-dev \
libssl-dev \
python-dev \
python-pip \
python3-dev \
python3-pip \
python3-venv \
rpm \
wget \
zip \
mysql-server \
python-mysqldb
python3-mysqldb

RUN pip install --upgrade --no-cache-dir pip virtualenv && \
virtualenv --system-site-packages $GRR_VENV
RUN pip3 install --upgrade setuptools && \
python3 -m venv --system-site-packages $GRR_VENV

RUN $GRR_VENV/bin/pip install --upgrade --no-cache-dir wheel six setuptools nodeenv && \
RUN $GRR_VENV/bin/pip install --upgrade --no-cache-dir pip wheel six setuptools nodeenv && \
$GRR_VENV/bin/nodeenv -p --prebuilt --node=12.11.1 && \
echo '{ "allow_root": true }' > /root/.bowerrc

# Copy the GRR code over.
ADD . /usr/src/grr

RUN cd /usr/src/grr && /usr/src/grr/docker/install_grr_from_gcs.sh
RUN cd /usr/src/grr && bash -x /usr/src/grr/docker/install_grr_from_gcs.sh

ENTRYPOINT ["/usr/src/grr/docker/docker-entrypoint.sh"]

Expand Down
16 changes: 15 additions & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@ APPLICATION=$1;
VIRTUALENV="/usr/share/grr-server/"
if [[ ${APPLICATION} = 'grr' ]]; then
if [[ "${DISABLE_INTERNAL_MYSQL}" != 'true' ]]; then
service mysql start
# Start the "inherited" mariadb:bionic entrypoint.
# See: https://github.com/docker-library/mariadb/blob/master/10.1/Dockerfile
gosu mysql bash -x <<EOF
export MYSQL_ALLOW_EMPTY_PASSWORD=1
source docker-entrypoint.sh
mysql_check_config mysqld
docker_setup_env mysqld
docker_create_db_directories
docker_verify_minimum_env
docker_init_database_dir mysqld
docker_temp_server_start mysqld
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*
EOF
fi
source "${VIRTUALENV}/bin/activate"

Expand Down
2 changes: 1 addition & 1 deletion docker/install_grr_from_gcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cd "${WORK_DIR}"
wget --quiet https://storage.googleapis.com/pub/gsutil.tar.gz
tar xzf gsutil.tar.gz

gsutil/gsutil cp "gs://${GCS_BUCKET}/*_${GRR_COMMIT}/travis_job_*server_deb/grr-server_*.tar.gz" .
python3 gsutil/gsutil cp "gs://${GCS_BUCKET}/*_${GRR_COMMIT}/travis_job_*server_deb/grr-server_*.tar.gz" .

tar xzf grr-server_*.tar.gz

Expand Down
48 changes: 48 additions & 0 deletions grr/server/grr_response_server/databases/db_clients_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,5 +1814,53 @@ def testDeleteClientNoAdditionalData(self):
with self.assertRaises(db.UnknownClientError):
self.db.ReadClientMetadata(client_id)

def testDeleteClientWithAssociatedMetadata(self):
client_id = db_test_utils.InitializeClient(self.db)

snapshot = rdf_objects.ClientSnapshot()
snapshot.client_id = client_id
snapshot.os_version = "3.14"
snapshot.arch = "i686"
snapshot.knowledge_base.os = "redox"
snapshot.knowledge_base.os_major_version = 3
snapshot.knowledge_base.os_minor_version = 14
self.db.WriteClientSnapshot(snapshot)

startup = rdf_client.StartupInfo()
startup.boot_time = rdfvalue.RDFDatetime.Now()
startup.client_info.client_version = 1337
self.db.WriteClientStartupInfo(client_id, startup)

crash = rdf_client.ClientCrash()
crash.client_id = client_id
crash.client_info.client_version = 1337
crash.timestamp = rdfvalue.RDFDatetime.Now()
self.db.WriteClientCrashInfo(client_id, crash)

self.db.DeleteClient(client_id)

with self.assertRaises(db.UnknownClientError):
self.db.ReadClientFullInfo(client_id)

def testDeleteClientWithPaths(self):
client_id = db_test_utils.InitializeClient(self.db)

path_info_0 = rdf_objects.PathInfo.OS(components=("foo", "bar", "baz"))
path_info_0.stat_entry.st_size = 42

path_info_1 = rdf_objects.PathInfo.OS(components=("foo", "bar", "quux"))
path_info_1.hash_entry.sha256 = b"quux"

path_info_2 = rdf_objects.PathInfo.OS(components=("foo", "norf", "thud"))
path_info_2.stat_entry.st_size = 1337
path_info_2.hash_entry.sha256 = b"norf"

self.db.WritePathInfos(client_id, [path_info_0, path_info_1, path_info_2])

self.db.DeleteClient(client_id)

with self.assertRaises(db.UnknownClientError):
self.db.ReadClientFullInfo(client_id)


# This file is a test library and thus does not require a __main__ block.
Loading

0 comments on commit 3440b00

Please sign in to comment.