uniformed xml configuration attributes, added max-request-size parameter
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
FROM alpine:latest AS base-release
|
FROM 21-jre-alpine AS base-release
|
||||||
RUN --mount=type=cache,target=/var/cache/apk apk update
|
|
||||||
RUN --mount=type=cache,target=/var/cache/apk apk add openjdk21-jre
|
|
||||||
RUN adduser -D luser
|
RUN adduser -D luser
|
||||||
USER luser
|
USER luser
|
||||||
WORKDIR /home/luser
|
WORKDIR /home/luser
|
||||||
|
@@ -21,6 +21,7 @@ public class Configuration {
|
|||||||
Authentication authentication;
|
Authentication authentication;
|
||||||
Tls tls;
|
Tls tls;
|
||||||
boolean useVirtualThread;
|
boolean useVirtualThread;
|
||||||
|
int maxRequestSize;
|
||||||
|
|
||||||
@Value
|
@Value
|
||||||
public static class Group {
|
public static class Group {
|
||||||
@@ -107,7 +108,8 @@ public class Configuration {
|
|||||||
Cache cache,
|
Cache cache,
|
||||||
Authentication authentication,
|
Authentication authentication,
|
||||||
Tls tls,
|
Tls tls,
|
||||||
boolean useVirtualThread
|
boolean useVirtualThread,
|
||||||
|
int maxRequestSize
|
||||||
) {
|
) {
|
||||||
return new Configuration(
|
return new Configuration(
|
||||||
host,
|
host,
|
||||||
@@ -118,7 +120,8 @@ public class Configuration {
|
|||||||
cache,
|
cache,
|
||||||
authentication,
|
authentication,
|
||||||
tls,
|
tls,
|
||||||
useVirtualThread
|
useVirtualThread,
|
||||||
|
maxRequestSize
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -7,6 +7,7 @@ import io.netty.channel.Channel
|
|||||||
import io.netty.channel.ChannelDuplexHandler
|
import io.netty.channel.ChannelDuplexHandler
|
||||||
import io.netty.channel.ChannelFuture
|
import io.netty.channel.ChannelFuture
|
||||||
import io.netty.channel.ChannelFutureListener
|
import io.netty.channel.ChannelFutureListener
|
||||||
|
import io.netty.channel.ChannelHandler.Sharable
|
||||||
import io.netty.channel.ChannelHandlerContext
|
import io.netty.channel.ChannelHandlerContext
|
||||||
import io.netty.channel.ChannelInitializer
|
import io.netty.channel.ChannelInitializer
|
||||||
import io.netty.channel.ChannelOption
|
import io.netty.channel.ChannelOption
|
||||||
@@ -77,6 +78,23 @@ import javax.net.ssl.SSLPeerUnverifiedException
|
|||||||
|
|
||||||
|
|
||||||
class GradleBuildCacheServer(private val cfg: Configuration) {
|
class GradleBuildCacheServer(private val cfg: Configuration) {
|
||||||
|
private val log = contextLogger()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
val DEFAULT_CONFIGURATION_URL by lazy { "classpath:net/woggioni/gbcs/gbcs-default.xml".toUrl() }
|
||||||
|
|
||||||
|
fun loadConfiguration(configurationFile: Path): Configuration {
|
||||||
|
val doc = Files.newInputStream(configurationFile).use {
|
||||||
|
Xml.parseXml(configurationFile.toUri().toURL(), it)
|
||||||
|
}
|
||||||
|
return Parser.parse(doc)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun dumpConfiguration(conf: Configuration, outputStream: OutputStream) {
|
||||||
|
Xml.write(Serializer.serialize(conf), outputStream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class HttpChunkContentCompressor(
|
private class HttpChunkContentCompressor(
|
||||||
threshold: Int,
|
threshold: Int,
|
||||||
@@ -107,10 +125,6 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
private val groupExtractor: Configuration.GroupExtractor?,
|
private val groupExtractor: Configuration.GroupExtractor?,
|
||||||
) : AbstractNettyHttpAuthenticator(authorizer) {
|
) : AbstractNettyHttpAuthenticator(authorizer) {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val log = contextLogger()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun authenticate(ctx: ChannelHandlerContext, req: HttpRequest): Set<Role>? {
|
override fun authenticate(ctx: ChannelHandlerContext, req: HttpRequest): Set<Role>? {
|
||||||
return try {
|
return try {
|
||||||
sslEngine.session.peerCertificates.takeIf {
|
sslEngine.session.peerCertificates.takeIf {
|
||||||
@@ -130,10 +144,7 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
private class NettyHttpBasicAuthenticator(
|
private class NettyHttpBasicAuthenticator(
|
||||||
private val users: Map<String, Configuration.User>, authorizer: Authorizer
|
private val users: Map<String, Configuration.User>, authorizer: Authorizer
|
||||||
) : AbstractNettyHttpAuthenticator(authorizer) {
|
) : AbstractNettyHttpAuthenticator(authorizer) {
|
||||||
|
private val log = contextLogger()
|
||||||
companion object {
|
|
||||||
private val log = contextLogger()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun authenticate(ctx: ChannelHandlerContext, req: HttpRequest): Set<Role>? {
|
override fun authenticate(ctx: ChannelHandlerContext, req: HttpRequest): Set<Role>? {
|
||||||
val authorizationHeader = req.headers()[HttpHeaderNames.AUTHORIZATION] ?: let {
|
val authorizationHeader = req.headers()[HttpHeaderNames.AUTHORIZATION] ?: let {
|
||||||
@@ -183,6 +194,14 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
private val eventExecutorGroup: EventExecutorGroup
|
private val eventExecutorGroup: EventExecutorGroup
|
||||||
) : ChannelInitializer<Channel>() {
|
) : ChannelInitializer<Channel>() {
|
||||||
|
|
||||||
|
private val serverHandler = let {
|
||||||
|
val cacheImplementation = cfg.cache.materialize()
|
||||||
|
val prefix = Path.of("/").resolve(Path.of(cfg.serverPath ?: "/"))
|
||||||
|
ServerHandler(cacheImplementation, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val exceptionHandler = ExceptionHandler()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun createSslCtx(tls: Configuration.Tls): SslContext {
|
private fun createSslCtx(tls: Configuration.Tls): SslContext {
|
||||||
val keyStore = tls.keyStore
|
val keyStore = tls.keyStore
|
||||||
@@ -287,17 +306,16 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
pipeline.addLast(HttpServerCodec())
|
pipeline.addLast(HttpServerCodec())
|
||||||
pipeline.addLast(HttpChunkContentCompressor(1024))
|
pipeline.addLast(HttpChunkContentCompressor(1024))
|
||||||
pipeline.addLast(ChunkedWriteHandler())
|
pipeline.addLast(ChunkedWriteHandler())
|
||||||
pipeline.addLast(HttpObjectAggregator(Int.MAX_VALUE))
|
pipeline.addLast(HttpObjectAggregator(cfg.maxRequestSize))
|
||||||
authenticator?.let {
|
authenticator?.let {
|
||||||
pipeline.addLast(it)
|
pipeline.addLast(it)
|
||||||
}
|
}
|
||||||
val cacheImplementation = cfg.cache.materialize()
|
pipeline.addLast(eventExecutorGroup, serverHandler)
|
||||||
val prefix = Path.of("/").resolve(Path.of(cfg.serverPath ?: "/"))
|
pipeline.addLast(exceptionHandler)
|
||||||
pipeline.addLast(eventExecutorGroup, ServerHandler(cacheImplementation, prefix))
|
|
||||||
pipeline.addLast(ExceptionHandler())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sharable
|
||||||
private class ExceptionHandler : ChannelDuplexHandler() {
|
private class ExceptionHandler : ChannelDuplexHandler() {
|
||||||
private val log = contextLogger()
|
private val log = contextLogger()
|
||||||
|
|
||||||
@@ -338,12 +356,11 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sharable
|
||||||
private class ServerHandler(private val cache: Cache, private val serverPrefix: Path) :
|
private class ServerHandler(private val cache: Cache, private val serverPrefix: Path) :
|
||||||
SimpleChannelInboundHandler<FullHttpRequest>() {
|
SimpleChannelInboundHandler<FullHttpRequest>() {
|
||||||
|
|
||||||
companion object {
|
private val log = contextLogger()
|
||||||
private val log = contextLogger()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun channelRead0(ctx: ChannelHandlerContext, msg: FullHttpRequest) {
|
override fun channelRead0(ctx: ChannelHandlerContext, msg: FullHttpRequest) {
|
||||||
val keepAlive: Boolean = HttpUtil.isKeepAlive(msg)
|
val keepAlive: Boolean = HttpUtil.isKeepAlive(msg)
|
||||||
@@ -448,8 +465,8 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
private val executorGroups: Iterable<EventExecutorGroup>
|
private val executorGroups: Iterable<EventExecutorGroup>
|
||||||
) : AutoCloseable {
|
) : AutoCloseable {
|
||||||
private val httpChannel: Channel = httpChannelFuture.channel()
|
private val httpChannel: Channel = httpChannelFuture.channel()
|
||||||
|
|
||||||
private val closeFuture: ChannelFuture = httpChannel.closeFuture()
|
private val closeFuture: ChannelFuture = httpChannel.closeFuture()
|
||||||
|
private val log = contextLogger()
|
||||||
|
|
||||||
fun shutdown(): ChannelFuture {
|
fun shutdown(): ChannelFuture {
|
||||||
return httpChannel.close()
|
return httpChannel.close()
|
||||||
@@ -501,22 +518,4 @@ class GradleBuildCacheServer(private val cfg: Configuration) {
|
|||||||
}
|
}
|
||||||
return ServerHandle(httpChannel, setOf(bossGroup, workerGroup, eventExecutorGroup))
|
return ServerHandle(httpChannel, setOf(bossGroup, workerGroup, eventExecutorGroup))
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
val DEFAULT_CONFIGURATION_URL by lazy { "classpath:net/woggioni/gbcs/gbcs-default.xml".toUrl() }
|
|
||||||
|
|
||||||
fun loadConfiguration(configurationFile: Path): Configuration {
|
|
||||||
val doc = Files.newInputStream(configurationFile).use {
|
|
||||||
Xml.parseXml(configurationFile.toUri().toURL(), it)
|
|
||||||
}
|
|
||||||
return Parser.parse(doc)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dumpConfiguration(conf: Configuration, outputStream: OutputStream) {
|
|
||||||
Xml.write(Serializer.serialize(conf), outputStream)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val log = contextLogger()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -31,8 +31,10 @@ object Parser {
|
|||||||
var groups = emptyMap<String, Group>()
|
var groups = emptyMap<String, Group>()
|
||||||
var tls: Tls? = null
|
var tls: Tls? = null
|
||||||
val serverPath = root.renderAttribute("path")
|
val serverPath = root.renderAttribute("path")
|
||||||
val useVirtualThread = root.renderAttribute("useVirtualThreads")
|
val useVirtualThread = root.renderAttribute("use-virtual-threads")
|
||||||
?.let(String::toBoolean) ?: true
|
?.let(String::toBoolean) ?: true
|
||||||
|
val maxRequestSize = root.renderAttribute("max-request-size")
|
||||||
|
?.let(String::toInt) ?: 67108864
|
||||||
var authentication: Authentication? = null
|
var authentication: Authentication? = null
|
||||||
for (child in root.asIterable()) {
|
for (child in root.asIterable()) {
|
||||||
val tagName = child.localName
|
val tagName = child.localName
|
||||||
@@ -136,7 +138,7 @@ object Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Configuration(host, port, serverPath, users, groups, cache!!, authentication, tls, useVirtualThread)
|
return Configuration(host, port, serverPath, users, groups, cache!!, authentication, tls, useVirtualThread, maxRequestSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseRoles(root: Element) = root.asIterable().asSequence().map {
|
private fun parseRoles(root: Element) = root.asIterable().asSequence().map {
|
||||||
|
@@ -14,7 +14,8 @@ object Serializer {
|
|||||||
it.xmlNamespace to it.xmlSchemaLocation
|
it.xmlNamespace to it.xmlSchemaLocation
|
||||||
}.toMap()
|
}.toMap()
|
||||||
return Xml.of(GBCS.GBCS_NAMESPACE_URI, GBCS.GBCS_PREFIX + ":server") {
|
return Xml.of(GBCS.GBCS_NAMESPACE_URI, GBCS.GBCS_PREFIX + ":server") {
|
||||||
attr("useVirtualThreads", conf.isUseVirtualThread.toString())
|
attr("use-virtual-threads", conf.isUseVirtualThread.toString())
|
||||||
|
attr("max-request-size", conf.maxRequestSize.toString())
|
||||||
// attr("xmlns:xs", GradleBuildCacheServer.XML_SCHEMA_NAMESPACE_URI)
|
// attr("xmlns:xs", GradleBuildCacheServer.XML_SCHEMA_NAMESPACE_URI)
|
||||||
val value = schemaLocations.asSequence().map { (k, v) -> "$k $v" }.joinToString(" ")
|
val value = schemaLocations.asSequence().map { (k, v) -> "$k $v" }.joinToString(" ")
|
||||||
attr("xs:schemaLocation", value , namespaceURI = GBCS.XML_SCHEMA_NAMESPACE_URI)
|
attr("xs:schemaLocation", value , namespaceURI = GBCS.XML_SCHEMA_NAMESPACE_URI)
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<gbcs:server useVirtualThreads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
<gbcs:server use-virtual-threads="false"
|
||||||
|
max-request-size="67108864"
|
||||||
|
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
||||||
xs:schemaLocation="urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
xs:schemaLocation="urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
||||||
<bind host="127.0.0.1" port="8080"/>
|
<bind host="127.0.0.1" port="8080"/>
|
||||||
|
@@ -23,7 +23,8 @@
|
|||||||
<xs:element name="tls" type="gbcs:tlsType" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="tls" type="gbcs:tlsType" minOccurs="0" maxOccurs="1"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
<xs:attribute name="path" type="xs:string" use="optional"/>
|
<xs:attribute name="path" type="xs:string" use="optional"/>
|
||||||
<xs:attribute name="useVirtualThreads" type="xs:boolean" use="optional" default="true"/>
|
<xs:attribute name="use-virtual-threads" type="xs:boolean" use="optional" default="true"/>
|
||||||
|
<xs:attribute name="max-request-size" type="xs:unsignedInt" use="optional" default="67108864"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="bindType">
|
<xs:complexType name="bindType">
|
||||||
|
@@ -45,6 +45,7 @@ abstract class AbstractBasicAuthServerTest : AbstractServerTest() {
|
|||||||
Configuration.BasicAuthentication(),
|
Configuration.BasicAuthentication(),
|
||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
|
0x10000
|
||||||
)
|
)
|
||||||
Xml.write(Serializer.serialize(cfg), System.out)
|
Xml.write(Serializer.serialize(cfg), System.out)
|
||||||
}
|
}
|
||||||
|
@@ -157,6 +157,7 @@ abstract class AbstractTlsServerTest : AbstractServerTest() {
|
|||||||
true
|
true
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
|
0x10000
|
||||||
)
|
)
|
||||||
Xml.write(Serializer.serialize(cfg), System.out)
|
Xml.write(Serializer.serialize(cfg), System.out)
|
||||||
}
|
}
|
||||||
|
@@ -46,6 +46,7 @@ class NoAuthServerTest : AbstractServerTest() {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
|
0x10000
|
||||||
)
|
)
|
||||||
Xml.write(Serializer.serialize(cfg), System.out)
|
Xml.write(Serializer.serialize(cfg), System.out)
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<gbcs:server useVirtualThreads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
<gbcs:server use-virtual-threads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
||||||
xs:schemaLocation="urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
xs:schemaLocation="urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
||||||
<bind host="127.0.0.1" port="11443"/>
|
<bind host="127.0.0.1" port="11443"/>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<gbcs:server useVirtualThreads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
<gbcs:server use-virtual-threads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
||||||
xmlns:gbcs-memcached="urn:net.woggioni.gbcs.server.memcached"
|
xmlns:gbcs-memcached="urn:net.woggioni.gbcs.server.memcached"
|
||||||
xs:schemaLocation="urn:net.woggioni.gbcs.server.memcached jpms://net.woggioni.gbcs.server.memcached/net/woggioni/gbcs/server/memcached/schema/gbcs-memcached.xsd urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
xs:schemaLocation="urn:net.woggioni.gbcs.server.memcached jpms://net.woggioni.gbcs.server.memcached/net/woggioni/gbcs/server/memcached/schema/gbcs-memcached.xsd urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<gbcs:server useVirtualThreads="false" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
<gbcs:server use-virtual-threads="false" max-request-size="4096" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
xmlns:gbcs="urn:net.woggioni.gbcs.server"
|
||||||
xs:schemaLocation="urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
xs:schemaLocation="urn:net.woggioni.gbcs.server jpms://net.woggioni.gbcs.server/net/woggioni/gbcs/server/schema/gbcs.xsd">
|
||||||
<bind host="127.0.0.1" port="11443"/>
|
<bind host="127.0.0.1" port="11443"/>
|
||||||
|
Reference in New Issue
Block a user