Skip to content

Commit

Permalink
fix(apache): fix root permission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jul 21, 2024
1 parent 59ab3df commit f4cc77e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion apache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Apache HTTPD server plugin for FluentCI"
edition = "2021"
license = "MIT"
name = "apache"
version = "0.1.2"
version = "0.1.3"

[lib]
crate-type = [
Expand Down
2 changes: 1 addition & 1 deletion apache/fluentci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ keywords = [
]
license = "MIT"
name = "apache"
version = "0.1.2"
version = "0.1.3"
8 changes: 4 additions & 4 deletions apache/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ LoadModule log_config_module modules/mod_log_config.so
Require all denied
</Directory>

DocumentRoot "${HTTPD_CONFDIR}/../"
<Directory "${HTTPD_CONFDIR}/../">
DocumentRoot "${HTTPD_CONFDIR}/../../"
<Directory "${HTTPD_CONFDIR}/../../">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Expand All @@ -49,9 +49,9 @@ CustomLog "${HTTPD_ACCESS_LOG_FILE}" access
ServerName php_localhost

UseCanonicalName Off
DocumentRoot "${HTTPD_CONFDIR}/../"
DocumentRoot "${HTTPD_CONFDIR}/../../"

<Directory "${HTTPD_CONFDIR}/../">
<Directory "${HTTPD_CONFDIR}/../../">
Options All
AllowOverride All
<IfModule mod_authz_host.c>
Expand Down
17 changes: 16 additions & 1 deletion apache/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub fn setup() -> Result<String, Error> {
let httpd_confdir = dag().get_env("HTTPD_CONFDIR")?;
let httpd_error_log_file = dag().get_env("HTTPD_ERROR_LOG_FILE")?;
let httpd_access_log_file = dag().get_env("HTTPD_ACCESS_LOG_FILE")?;
let is_root = dag()
.pkgx()?
.with_exec(vec!["whoami"])?
.stdout()?
.contains("root");

if httpd_port.is_empty() {
dag().set_envs(vec![("HTTPD_PORT".into(), "8080".into())])?;
Expand Down Expand Up @@ -60,7 +65,17 @@ pub fn setup() -> Result<String, Error> {
.with_exec(vec!["[ -f httpd.conf ] || flox activate -- wget https://raw.githubusercontent.com/fluentci-io/services/main/apache/httpd.conf"])?
.with_exec(vec!["[ -f ../../index.html ] || flox activate -- wget https://raw.githubusercontent.com/fluentci-io/services/main/apache/web/index.html -O ../../index.html"])?
.with_exec(vec![
"grep -q web Procfile || echo -e 'web: apachectl start -f $PWD/httpd.conf -D FOREGROUND\\n' >> Procfile",
match is_root {
true => "chown -R fluentci /root /nix && chown -R root /root/.cache",
false => "true"
}
])?
.with_exec(vec![
match is_root {
true => "grep -q web Procfile || echo -e 'web: sudo -H -E -u fluentci PATH=$PATH bash -c \"flox activate -- apachectl start -f $PWD/httpd.conf -D FOREGROUND \" \\n' >> Procfile",
false => "grep -q web Procfile || echo -e 'web: apachectl start -f $PWD/httpd.conf -D FOREGROUND\\n' >> Procfile"
}
,
])?
.stdout()?;

Expand Down
4 changes: 3 additions & 1 deletion apache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod helpers;
#[plugin_fn]
pub fn start(_args: String) -> FnResult<String> {
helpers::setup()?;

let port = dag().get_env("HTTPD_PORT")?;
let stdout = dag()
.flox()?
.with_workdir(".fluentci/apache")?
Expand All @@ -19,7 +21,7 @@ pub fn start(_args: String) -> FnResult<String> {
.with_exec(vec![
"overmind start -f Procfile --daemonize || flox activate -- overmind restart web",
])?
.with_exec(vec!["sleep", "3"])?
.wait_on(port.parse()?, timeout)
.with_exec(vec!["overmind", "status"])?
.with_exec(vec!["curl", "-s", "http://localhost:$HTTPD_PORT"])?
.stdout()?;
Expand Down
2 changes: 1 addition & 1 deletion postgres/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn setup() -> Result<String, Error> {
])?
.with_exec(vec![
match is_root {
true => "chown -R fluentci /root /nix",
true => "chown -R fluentci /root /nix && chown -R root /root/.cache",
false => "true"
}
])?
Expand Down

0 comments on commit f4cc77e

Please sign in to comment.