Skip to content

Instantly share code, notes, and snippets.

View asardaes's full-sized avatar

Alexis Sardá asardaes

View GitHub Profile
@asardaes
asardaes / README.md
Created August 23, 2026 20:11
Mitigate crowdsec 401 and 403 false positives for Traefik and OIDC

When Traefik is acting as reverse proxy with some form of OIDC integration, the expectation is that 401 and 403 statuses are returned before any upstream services are contacted, assuming that all endpoints and resources are protected by some OIDC bouncing mechanism. In this case, seeing 401/403 in Traefik's access logs should mean that OIDC auth was present and valid, and some other issue occurred in the upstream service.

If crowdsec is in use and it's ingesting Traefik's access logs, bans may be triggered due to LePresidente/http-generic-401-bf or LePresidente/http-generic-403-bf. To mitigate this, ensure the access logs include OriginStatus and add the YAMLs below to crowdsec (replace | with / to get the right path).

@asardaes
asardaes / cmds.sh
Created October 9, 2025 18:42
Debloat Oracle Ubuntu
sudo systemctl disable --now apt-daily.timer
sudo systemctl disable --now apt-daily-upgrade.timer
sudo apt-get purge unattended-upgrades
sudo snap remove oracle-cloud-agent
@asardaes
asardaes / StreamingJsonBodyExtractor.java
Last active August 13, 2025 14:05 — forked from HaloFour/StreamingJsonBodyExtractor.java
Streaming JSON Body Extractor
package org.test;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.async.ByteBufferFeeder;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.TokenBuffer;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ResolvableType;
@asardaes
asardaes / app.py
Last active September 23, 2024 16:04
Shiny app in Python hacked to support OAuth2 authorization code *for client requests*
import typing
import uuid
from urllib.parse import urlparse
from requests_oauthlib.oauth2_session import OAuth2Session
from shiny import App
from shiny._connection import StarletteConnection
from shiny.session._session import AppSession
from starlette.applications import Starlette
from starlette.middleware import Middleware
@asardaes
asardaes / SetSerializer.java
Last active August 14, 2023 13:05
Flink set serialization for POJOs
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot;
import org.apache.flink.api.common.typeutils.base.ListSerializer;
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataOutputView;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
@asardaes
asardaes / CustomJwtBearerTokenResponseClient.kt
Last active July 6, 2026 20:13
Configuring Spring's WebClient for OAuth2 JWT Bearer Client Authentication (client_secret_jwt with private key) - MVC non-reactive version
// Salesforce doesn't include expires_in in its token response, so Spring assumes it's only valid for 1 second.
// Considering clock skew logic, each token is basically valid for a single call,
// so you might want to force the assumption that it can be valid for a little longer.
class CustomJwtBearerTokenResponseClient(
private val minimumTokenDuration: Duration
) : OAuth2AccessTokenResponseClient<JwtBearerGrantRequest> {
private val defaultClient = DefaultJwtBearerTokenResponseClient()
override fun getTokenResponse(authorizationGrantRequest: JwtBearerGrantRequest): OAuth2AccessTokenResponse {
@asardaes
asardaes / Test.kt
Created October 14, 2022 10:12
Flink test for broadcast state
@Test
fun `snapshot and subsequent restore`() {
// non-empty function (knows about active customers)
val function = getFunctionForTesting()
val (operatorId, stateFinalizer) = getHarness(function).use { harness ->
harness.processBroadcastElement(GenericChangeMessage(), 1L)
val stateFinalizer = harness.snapshotWithLocalState(0L, 1L)
assertEquals(1, stateFinalizer.jobManagerOwnedState.managedOperatorState.size)
Pair(harness.streamConfig.operatorID, stateFinalizer)
}
@asardaes
asardaes / StateCounts.kt
Last active April 11, 2022 15:10
Flink State Processor API Sample
// kotlin POJO
import java.io.Serializable
data class StateCounts(
var windowState: Int = 0,
var globalState: Int = 0,
var windows: Int = 0,
var dtos: Int = 0,
val dtoBytes: Long = 0L,
) : Serializable {
@asardaes
asardaes / README.txt
Last active April 15, 2023 12:33
Publishing a Gradle precompiled script plugin to a custom repository
Gradle plugins require a marker:
https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
Markers aren't published for precompiled scripts using groovy-gradle-plugin :(
https://github.com/gradle/gradle/issues/15190
The plugin_marker module creates the marker that Gradle needs to find the plugin and also publishes it,
see https://stackoverflow.com/a/60798021/5793905
Assuming all gradle modules have the same group with a folder structure like:
@asardaes
asardaes / Main.kt
Created June 3, 2019 12:14
Flink dynamic Key Selector
data class WC(var word: String, var count: Int) : Serializable {
constructor() : this("", 0)
}
class KS : KeySelector<WC, Int> {
private var count = 0
override fun getKey(value: WC): Int {
println("count=$count, value=$value")
return if (count++ < 2) 0 else 1
}