Skip to content

Aggregate nginx logs across all Pantheon app containers - #1052

Open
AronNovak wants to merge 1 commit into
mainfrom
security-multiple-app-containers
Open

Aggregate nginx logs across all Pantheon app containers#1052
AronNovak wants to merge 1 commit into
mainfrom
security-multiple-app-containers

Conversation

@AronNovak

Copy link
Copy Markdown
Member

Pantheon environments can run on multiple application containers, each keeping its own nginx logs. getLogFile() only fetched logs from the single container returned by terminus connection:info --field=sftp_command, so the DDoS / access-log analysis saw only a fraction of the traffic.

Now resolve every container IP behind the appserver hostname and aggregate their nginx-access.log into one file before analysis.

Ref: https://docs.pantheon.io/guides/logs-pantheon/automate-log-downloads

@mariano-dagostino mariano-dagostino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AronNovak oh good find! Looks good, but I have some changes to propose.

protected function getLogFile(string $env) {
$pantheon_info = $this->getPantheonNameAndEnv();
$this->_exec('$(terminus connection:info --field=sftp_command ' . $pantheon_info['name'] . ".$env) <<EOF
$site_env = $pantheon_info['name'] . ".$env";

@mariano-dagostino mariano-dagostino Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AronNovak What about making the getLogFile a public method so it can be used to download logs outside the scope of checking bots?

Comment on lines +206 to +208
$sftp_username = trim($this->getTerminusConnectionField($site_env, 'sftp_username'));
$sftp_host = trim($this->getTerminusConnectionField($site_env, 'sftp_host'));
$sftp_port = trim($this->getTerminusConnectionField($site_env, 'sftp_port')) ?: '2222';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terminus connection:info site.env --format=json --fields=sftp_username,sftp_port,sftp_host

returns the 3 values we need as json format. in a single call.

* @return string
* The field value, or an empty string when it could not be retrieved.
*/
protected function getTerminusConnectionField(string $site_env, string $field): string {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed in my opinion, see the --fields param above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants