Commit Graph

74 Commits

Author SHA1 Message Date
Andras Bacsai 858b1906ec Improve GitHub App setup flow 2026-06-03 09:33:46 +02:00
Andras Bacsai 34f15c106c fix(webhook): match GitLab SSH repos with custom ports
Strip leading port segments from scp-style GitLab repository URLs so manual webhook matching compares the repository path consistently. Cover both ported and unported SSH URL forms.
2026-05-31 21:46:23 +02:00
ShadowArcanist ab4b2045d4 fix(webhook): skip preview deployments for fork PRs when public previews are off 2026-05-29 23:53:51 +05:30
Andras Bacsai 5a7408a919 fix(github): improve GitHub App setup and installation flow
- resolve the GitHub App by a stable identifier during installation
  callbacks so installing and re-installing keeps working over the
  full lifetime of the App
- verify the installation id received from the callback against the
  GitHub API before persisting it
- support re-installing an already configured GitHub App instead of
  blocking it
- require an authenticated session and rate limit the setup callback
  routes
- extend manifest setup state validity to match GitHub's manifest
  code lifetime

Adds feature coverage for the GitHub App setup and installation
callbacks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:34:36 +02:00
Andras Bacsai 809d9b21fa fix(webhook): match manual webhook repositories case-insensitively
Git hosts treat owner/repo names case-insensitively, but the exact
repository match used a case-sensitive comparison, so a payload whose
casing differed from the stored git remote would fail to match and
skip a legitimate deployment.

Lowercase both canonical repository paths before comparing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 15:59:20 +02:00
Andras Bacsai c1518ba1c0 fix(webhook): match manual webhook repositories exactly
The manual webhook handlers selected target applications with a
`git_repository LIKE %full_name%` substring query, so a payload
repository name could match unintended applications when repository
names overlap.

Add a `MatchesManualWebhookApplications` trait that validates the
incoming `owner/repo` value and matches `Application.git_repository`
by exact normalized path. Github, Gitlab, Gitea and Bitbucket manual
handlers now use it, reject invalid repository input early, and return
a consistent generic webhook failure payload.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 15:32:44 +02:00
Andras Bacsai 46180dbbf9 feat(webhook): skip deployment on [skip ci]/[skip cd] commit markers
Add DetectsSkipDeployCommits trait with two strategies: shouldSkipDeploy
(all commits must contain the marker) for push events, and
shouldSkipDeployAny (any single marker triggers skip) for PR/MR titles
and latest-commit signals.

Apply trait to Bitbucket, Gitea, GitHub, GitLab webhook controllers and
ProcessGithubPullRequestWebhook job. PRs pass pullRequestTitle through
to the job constructor for evaluation.
2026-04-29 09:12:24 +02:00
Andras Bacsai a2096c6f68 feat(observability): add structured audit log channel for API and webhook events
Introduce a dedicated `audit` log channel (daily rotation, configurable retention via
LOG_AUDIT_DAYS) and a small `auditLog()` / `auditLogWebhookFailure()` helper used to
record state-changing API operations and webhook events.

Instrumented:

- API mutation endpoints (create / update / delete / start / stop / restart) across
  applications, services, databases (incl. backups, env vars, storage), servers,
  projects + environments, scheduled tasks, private keys, GitHub apps, cloud provider
  tokens, Hetzner server provisioning, instance enable/disable.
- Webhook signature verification outcomes for GitHub, GitLab, Bitbucket, Gitea and
  Stripe, plus the Sentinel push endpoint.
- Authentication and authorization outcomes via the global exception handler and
  the `ApiAbility` middleware (unauthenticated, ability-denied, policy-denied).

The helper is wrapped in try/catch so logging failures never affect the request
path. Successful operations log at `info`; suspicious/denied requests log at
`warning`. Operators wanting a failures-only feed can set `LOG_AUDIT_LEVEL=warning`.

Includes a feature test suite covering the helper, the webhook providers and the
new auth/authorization log paths.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-28 14:50:37 +02:00
Andras Bacsai bafb9a5a8b refactor(webhook): encrypt manual webhook secrets and tighten HMAC verification
- Auto-generate a 40-char random secret for each manual_webhook_secret_* column on Application creation so new apps are never left with an empty secret.
- Add encrypted cast for the four webhook-secret columns; backfill migration re-encrypts existing plaintext values and fills missing ones.
- Reject webhook deliveries when the stored secret is empty (GitHub, GitLab, Bitbucket, Gitea manual endpoints).
- Bitbucket: require the sha256 algorithm prefix on X-Hub-Signature instead of trusting the client-supplied algo.
- GitLab: drop the ?? '' fallback on the token comparison.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-19 12:52:23 +02:00
Andras Bacsai 1a603a10ed fix(models): replace forceFill/forceCreate with fill/create and add fillable guards
Replace all uses of `forceFill`, `forceCreate`, and `forceFill` with their
non-force equivalents across models, actions, controllers, and Livewire
components. Add explicit `$fillable` arrays to all affected Eloquent models
to enforce mass assignment protection.

Add ModelFillableCreationTest and ModelFillableRegressionTest to verify that
model creation respects fillable constraints and prevent regressions.
2026-03-31 13:45:31 +02:00
Andras Bacsai 1da1f32f0e refactor: use forceCreate() for internal model creation
Replace create() with forceCreate() across internal model creation operations to bypass mass assignment protection. This is appropriate for internal code that constructs complete model state without user input.

Add InternalModelCreationMassAssignmentTest to ensure internal model creation behavior is properly tested. Optimize imports by using shortened Livewire attribute references and removing unused imports.
2026-03-30 13:04:11 +02:00
Andras Bacsai b931418c1e fix(github-webhook): handle unsupported event types gracefully
Add validation in manual and normal webhook handlers to reject GitHub
event types other than 'push' and 'pull_request'. Unsupported events
now return a graceful response instead of potentially causing
downstream errors. Includes tests for ping events, unsupported event
types, and unknown events.
2026-03-23 21:33:40 +01:00
peaklabs-dev 54a834e042 fix(git): trigger deployments when watch_paths is empty 2026-01-07 19:15:16 +01:00
Andras Bacsai 7a305fd2cd fix: prevent timing attack in GitLab webhook token validation
Replace insecure !== operator with hash_equals() for constant-time
string comparison when validating GitLab webhook tokens.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 15:23:48 +01:00
Andras Bacsai 162eaa9f0d feat(github): implement processing for GitHub pull request webhooks and add helper functions for commit and PR file retrieval 2026-01-05 11:13:18 +01:00
Andras Bacsai 0e47de81d1 Fix: Prevent double deployments when multiple GitHub Apps access same repository (#2315)
Filter webhook-triggered deployments by source_id to ensure only applications
associated with the GitHub App that sent the webhook are deployed, preventing
duplicate deployments when the same repository is configured in multiple teams.
2025-12-12 11:35:00 +01:00
Andras Bacsai 700550b26f Fix: Concurrent builds ignored & add deployment queue limit (#7488) 2025-12-11 11:03:02 +01:00
Andras Bacsai d019553809 Add Retry-After header to 429 rate limit responses
Adds Retry-After: 60 header to all deployment queue full responses,
helping webhook clients know when to retry their requests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-11 11:02:29 +01:00
Andras Bacsai d27070b215 fix: Add comprehensive PR cleanup to GitLab, Bitbucket, and Gitea webhooks
Create a shared CleanupPreviewDeployment action that unifies PR cleanup logic across all Git providers. Previously, GitHub had comprehensive cleanup (cancels active deployments, kills helper containers, removes all PR containers), while GitLab, Bitbucket, and Gitea only did basic cleanup (delete preview record and remove one container by name).

This fix ensures all providers properly clean up orphaned PR containers when a PR is closed/merged, preventing security issues and resource waste. Also fixes early return bug in GitLab webhook handler.

Fixes #2610

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-08 17:10:39 +01:00
Andras Bacsai 6d16f52143 Add deployment queue limit to prevent queue bombing
- Add configurable deployment_queue_limit server setting (default: 25)
- Check queue size before accepting new deployments
- Return 429 status for webhooks/API when queue is full (allows retry)
- Show error toast in UI when queue limit reached
- Add UI control in Server Advanced settings

Fixes #6708

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 13:52:27 +01:00
Andras Bacsai 158d54712f Remove webhook maintenance mode replay feature
This feature stored incoming webhooks during maintenance mode and replayed them
when maintenance ended. The behavior adds unnecessary complexity without clear
value. Standard approach is to let webhooks fail during maintenance and let
senders retry.

Removes:
- Listener classes that handled maintenance mode events and webhook replay
- Maintenance mode checks from all webhook controllers (Github, Gitea, Gitlab, Bitbucket, Stripe)
- webhooks-during-maintenance filesystem disk configuration
- Feature mention from CHANGELOG

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 13:36:32 +01:00
Andras Bacsai 0b8d3d395e fix: remove redundant process termination logic from deployment methods 2025-11-10 14:46:02 +01:00
Andras Bacsai 67605d50fc fix(deployment): prevent base deployments from being killed when PRs close (#7113)
- Fix container filtering to properly distinguish base deployments (pullRequestId=0) from PR deployments
- Add deployment cancellation when PR closes via webhook to prevent race conditions
- Prevent CleanupHelperContainersJob from killing active deployment containers
- Enhance error messages with exit codes and actual errors instead of vague "Oops" messages
- Protect status transitions in finally blocks to ensure proper job failure handling
2025-11-09 14:41:35 +01:00
Andras Bacsai d9ebf3b142 refactor(webhook): remove Webhook model and related logic; add migrations to drop webhooks and kubernetes tables 2025-09-10 19:35:53 +02:00
Andras Bacsai 52312e9de6 refactor(github-webhook): restructure application processing by grouping applications by server for improved deployment handling 2025-09-10 09:30:43 +02:00
Andras Bacsai 8c5c249c6a refactor(webhook): replace direct forceDelete calls with DeleteResourceJob dispatch for application previews 2025-09-05 19:27:59 +02:00
Andras Bacsai a10e51b2c4 fix(webhook): replace delete with forceDelete for application previews to ensure immediate removal 2025-09-05 17:50:33 +02:00
Andras Bacsai 339118558c feat(settings): add option to restrict PR deployments to repository members and contributors 2025-09-05 14:30:51 +02:00
Andras Bacsai 5bdf2e8481 refactor(previews): move preview domain generation logic to ApplicationPreview model for better encapsulation and consistency across webhook handlers 2025-07-14 19:12:57 +02:00
Andras Bacsai d075241289 feat(Deployment): enhance queue_application_deployment to handle existing deployments and return appropriate status messages 2025-04-11 15:27:56 +02:00
Andras Bacsai 337e12f5c6 Merge pull request #5245 from janwiebe-jump/fix-gitea
Gitea webhook sends action synchronized
2025-03-11 10:21:56 +01:00
janwiebe-jump 37553e79b7 Gitea webhook sends action synchronized 2025-02-27 17:25:33 +01:00
Andras Bacsai 27e4882d57 feat(core): You can validate compose files with docker compose config
fix(core): labels are now accepted with both compose styles
refactor: remove lots of ray's
2025-02-27 11:29:04 +01:00
Islam Adel 672a5d0bc5 fix: Handle pullrequest:updated for reliable preview deployments
The repo:push payload lacks the destination branch name, using push.changes.0.new.name instead. While sufficient for updates, this causes failures in preview deployments when a PR receives new commits—Coolify looks for git_branch in the applications table but finds the source branch instead.

By also processing pullrequest:updated, we ensure preview deployments remain in sync. However, this event triggers on various actions (e.g., PR title changes, reviewer updates), causing extra redeploys. Since Coolify doesn’t store commit hashes for preview deployments, handling these extra redeploys is our best workaround for Bitbucket.
2025-02-01 12:24:23 +02:00
peaklabs-dev d9248508b4 chore: remove unused waitlist stuff 2024-12-09 12:00:54 +01:00
peaklabs-dev 5f985426ab feat: update private key nam with new slug as well 2024-12-03 15:27:20 +01:00
Andras Bacsai 377758edcd fix stripe webhooks 2024-11-22 14:42:10 +01:00
Andras Bacsai 8e4060375d remove ray 2024-11-12 10:23:00 +01:00
Andras Bacsai da9c8eed16 Merge pull request #4194 from quarkcore/fix/gitlab-empty-webhook-secret
Fix: Gitlab webhooks can be triggered without secret
2024-11-12 10:22:36 +01:00
Andras Bacsai 1faa8be615 fix: cloud + stripe related 2024-11-11 22:18:15 +01:00
quarkcore 8ddc5d6ef7 Merge branch 'next' into fix/gitlab-empty-webhook-secret 2024-11-08 15:19:45 +01:00
Kolja Völker 88e6c04b73 Fixes: https://github.com/coollabsio/coolify/issues/4186 2024-11-08 15:15:58 +01:00
Andras Bacsai 4fa533aae8 Refactor webhook event handling logic 2024-11-01 00:07:01 +01:00
Andras Bacsai 5ce2422b90 fix: stripe webhooks
fix: add custome created webhook
2024-10-31 23:26:40 +01:00
Lucas Michot 8e1444eaa7 Get rid of many useless blank lines 2024-10-31 17:44:01 +01:00
Lucas Michot d557a22b91 Remove all ray() calls 2024-10-28 13:51:23 +01:00
andrasbacsai 96c4f5b8da Fix styling 2024-07-25 11:31:59 +00:00
Andras Bacsai 6a4aa492c0 fix: random generated uuid will be full length (not 7 characters) 2024-07-25 13:31:01 +02:00
Andras Bacsai a3a1ff69e1 fix: preview deployments should be stopped properly via gh webhook 2024-07-22 13:06:03 +02:00
Andras Bacsai 38d9999814 refactor: Simplify code for retrieving subscription in Stripe webhook 2024-07-06 13:47:43 +02:00