Skip to content

Commit

Permalink
chore: update circleci to use new docker auth
Browse files Browse the repository at this point in the history
NOTE: while libs and tests have been updated, audit would need to ignore
RUSTSEC-2020-0052 until `slog-async` is updated

Issue mozilla-services/services-engineering#71
  • Loading branch information
jrconlin committed Oct 14, 2020
1 parent addc42f commit a1b47f5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 39 deletions.
12 changes: 11 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
# DOCKER_USER
# DOCKER_PASS
#
version: 2
version: 2.1
defaults:
docker_login: &docker_login
run:
name: Login to Dockerhub
command: |
if [ "${DOCKER_USER}" == "" ] || [ "${DOCKER_PASS}" == "" ]; then
echo "Skipping Login to Dockerhub, no credentials."
else
echo "${DOCKER_PASS}" | docker login -u="${DOCKER_USER}" --password-stdin
fi
jobs:
build:
docker:
Expand Down
25 changes: 17 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ diesel_migrations = { version = "1.4.0", features = ["mysql"] }
failure = "0.1.6"
lazy_static = "1.4.0"
mozsvc-common = "0.1.1"
regex = "1.3.3"
regex = "1.4"
rocket = "0.4.2"
rocket_contrib = "0.4.2"
serde = "1.0.104"
serde_json = "1.0.44"
rocket_contrib = "0.4"
serde = "1.0"
serde_json = "1.0"
slog = { version = "2.5.2", features = ["nested-values"] }
slog-async = { version = "2.3.0", features = ["nested-values"] }
slog-async = { version = "2.5", features = ["nested-values"] } # 2.5 includes RUSTSEC-2020-0052
slog_derive = "0.2.0"
slog-mozlog-json = "0.1.0"
slog-term = "2.4.2"
slog-term = "2.6"
# must match the toml (minor) version rocket depends on
toml = "0.4.10"
toml = "0.5"
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ RUN \

FROM debian:buster-slim

MAINTAINER <[email protected]>

RUN \
groupadd --gid 10001 app && \
useradd --uid 10001 --gid 10001 --home /app --create-home app && \
Expand Down
42 changes: 31 additions & 11 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,37 @@ pub fn authorized_reader(request: &Request<'_>) -> HandlerResult<Reader> {
}

#[cfg(test)]
mod test {
use rocket::config::{Config, Environment};
use toml::{toml, toml_internal};
pub(crate) mod test {
use rocket::config::{Array, Config, Environment, Value};
use std::collections::BTreeMap;

use super::{BearerTokenAuthenticator, Group};

pub(crate) fn to_table(vals: Vec<&str>) -> BTreeMap<String, Vec<Value>> {
let mut table = BTreeMap::new();
{
for val in vals {
let mut vargs: Vec<Value> = Array::new();
let bits: Vec<&str> = val.splitn(2, "=").collect();
let key = bits[0];
let items = bits[1];
for item in items.split(",") {
vargs.push(item.into())
}
table.insert(key.into(), vargs);
}
}
table
}

#[test]
fn test_basic() {
let config = Config::build(Environment::Development)
.extra(
"broadcaster_auth",
toml! {foo = ["bar"] baz = ["quux", "wobble"]},
to_table(["foo=bar", "baz=quux,wobble"].to_vec()),
)
.extra("reader_auth", toml! {otto = ["push"]})
.extra("reader_auth", to_table(["otto=push"].to_vec()))
.unwrap();
let authenicator = BearerTokenAuthenticator::from_config(&config).unwrap();

Expand All @@ -193,26 +210,29 @@ mod test {
#[test]
fn test_dupe_token() {
let config = Config::build(Environment::Development)
.extra("broadcaster_auth", toml! {foo = ["bar"] baz = ["bar"]})
.extra("reader_auth", toml! {otto = ["push"]})
.extra(
"broadcaster_auth",
to_table(["foo=bar", "baz=bar"].to_vec()),
)
.extra("reader_auth", to_table(["otto=push"].to_vec()))
.unwrap();
assert!(BearerTokenAuthenticator::from_config(&config).is_err());
}

#[test]
fn test_dupe_token2() {
let config = Config::build(Environment::Development)
.extra("broadcaster_auth", toml! {foo = ["bar"]})
.extra("reader_auth", toml! {baz = ["quux", "bar"]})
.extra("broadcaster_auth", to_table(["foo=bar"].to_vec()))
.extra("reader_auth", to_table(["baz=quux,bar"].to_vec()))
.unwrap();
assert!(BearerTokenAuthenticator::from_config(&config).is_err());
}

#[test]
fn test_dupe_user() {
let config = Config::build(Environment::Development)
.extra("broadcaster_auth", toml! {foo = ["bar"]})
.extra("reader_auth", toml! {foo = ["baz"]})
.extra("broadcaster_auth", to_table(["foo=bar"].to_vec()))
.extra("reader_auth", to_table(["foo=baz"].to_vec()))
.unwrap();
assert!(BearerTokenAuthenticator::from_config(&config).is_err());
}
Expand Down
20 changes: 10 additions & 10 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ fn setup_rocket(rocket: Rocket) -> Result<Rocket> {

#[cfg(test)]
mod test {
use crate::auth::test::to_table;
use rocket;
use rocket::config::{Config, Environment, RocketConfig};
use rocket::config::{Config, Environment, RocketConfig, Value as RValue};
use rocket::http::{Header, Status};
use rocket::local::Client;
use rocket::response::Response;
use rocket_contrib::json;
use serde_json::{self, Value};
use toml::{toml, toml_internal};

use super::setup_rocket;

Expand Down Expand Up @@ -247,22 +247,22 @@ mod test {
let database_url = rconfig
.active()
.get_str("database_url")
.expect("ROCKET_DATABASE_URL undefined");

.expect("ROCKET_DATABASE_URL undefined").to_owned();
let config = Config::build(Environment::Development)
.extra("database_url", database_url)
.extra("database_url", RValue::String(database_url))
.extra("database_pool_max_size", 1)
.extra("database_use_test_transactions", true)
.extra("json_logging", false)
.extra(
"broadcaster_auth",
toml! {
foo = ["feedfacedeadbeef", "deadbeeffacefeed"]
baz = ["baada555deadbeef"]
},
to_table(["foo=feedfacedeadbeef,deadbeeffacefeed", "baz=baada555deadbeef"].to_vec())
)
.extra(
"reader_auth",
to_table(["reader=00000000deadbeef"].to_vec())
)
.extra("reader_auth", toml! {reader = ["00000000deadbeef"]})
.unwrap();
dbg!(&config);

let rocket = setup_rocket(rocket::custom(config)).expect("rocket failed");
Client::new(rocket).expect("rocket launch failed")
Expand Down

0 comments on commit a1b47f5

Please sign in to comment.