Skip to content

Commit 2cbc5bd

Browse files
committed
KAFKA-17636 Fix missing SCRAM bootstrap records (#17305)
Fixes a regression introduced by #16669 which inadvertently stopped processing SCRAM arguments from kafka-storage.sh Reviewers: Colin P. McCabe <cmccabe@apache.org>, Federico Valeri <fedevaleri@gmail.com>
1 parent 89cb632 commit 2cbc5bd

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

core/src/main/scala/kafka/tools/StorageTool.scala

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ object StorageTool extends Logging {
130130
if (namespace.getBoolean("standalone")) {
131131
formatter.setInitialVoters(createStandaloneDynamicVoters(config))
132132
}
133+
Option(namespace.getList("add_scram")).
134+
foreach(scramArgs => formatter.setScramArguments(scramArgs.asInstanceOf[util.List[String]]))
133135
configToLogDirectories(config).foreach(formatter.addDirectory(_))
134136
formatter.run()
135137
}

core/src/test/scala/unit/kafka/tools/StorageToolTest.scala

+49-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import java.io.{ByteArrayOutputStream, File, PrintStream}
2121
import java.nio.charset.StandardCharsets
2222
import java.nio.file.Files
2323
import java.util
24-
import java.util.Properties
24+
import java.util.{Optional, Properties}
2525
import kafka.server.KafkaConfig
2626
import kafka.utils.TestUtils
2727
import net.sourceforge.argparse4j.inf.ArgumentParserException
28+
import org.apache.kafka.common.metadata.UserScramCredentialRecord
2829
import org.apache.kafka.common.utils.Utils
2930
import org.apache.kafka.server.common.Features
31+
import org.apache.kafka.metadata.bootstrap.BootstrapDirectory
3032
import org.apache.kafka.metadata.properties.{MetaPropertiesEnsemble, PropertiesUtils}
3133
import org.apache.kafka.metadata.storage.FormatterException
3234
import org.apache.kafka.raft.QuorumConfig
@@ -37,6 +39,7 @@ import org.junit.jupiter.params.ParameterizedTest
3739
import org.junit.jupiter.params.provider.ValueSource
3840

3941
import scala.collection.mutable.ListBuffer
42+
import scala.jdk.CollectionConverters.IterableHasAsScala
4043

4144
@Timeout(value = 40)
4245
class StorageToolTest {
@@ -433,5 +436,49 @@ Found problem:
433436
contains("Formatting dynamic metadata voter directory %s".format(availableDirs.head)),
434437
"Failed to find content in output: " + stream.toString())
435438
}
436-
}
437439

440+
@Test
441+
def testBootstrapScramRecords(): Unit = {
442+
val availableDirs = Seq(TestUtils.tempDir())
443+
val properties = new Properties()
444+
properties.putAll(defaultDynamicQuorumProperties)
445+
properties.setProperty("log.dirs", availableDirs.mkString(","))
446+
val stream = new ByteArrayOutputStream()
447+
val arguments = ListBuffer[String](
448+
"--release-version", "3.9-IV0",
449+
"--add-scram", "SCRAM-SHA-512=[name=alice,password=changeit]",
450+
"--add-scram", "SCRAM-SHA-512=[name=bob,password=changeit]"
451+
)
452+
453+
assertEquals(0, runFormatCommand(stream, properties, arguments.toSeq))
454+
455+
// Not doing full SCRAM record validation since that's covered elsewhere.
456+
// Just checking that we generate the correct number of records
457+
val bootstrapMetadata = new BootstrapDirectory(availableDirs.head.toString, Optional.empty).read
458+
val scramRecords = bootstrapMetadata.records().asScala
459+
.filter(apiMessageAndVersion => apiMessageAndVersion.message().isInstanceOf[UserScramCredentialRecord])
460+
.map(apiMessageAndVersion => apiMessageAndVersion.message().asInstanceOf[UserScramCredentialRecord])
461+
.toList
462+
assertEquals(2, scramRecords.size)
463+
assertEquals("alice", scramRecords.head.name())
464+
assertEquals("bob", scramRecords.last.name())
465+
}
466+
467+
@Test
468+
def testScramRecordsOldReleaseVersion(): Unit = {
469+
val availableDirs = Seq(TestUtils.tempDir())
470+
val properties = new Properties()
471+
properties.putAll(defaultDynamicQuorumProperties)
472+
properties.setProperty("log.dirs", availableDirs.mkString(","))
473+
val stream = new ByteArrayOutputStream()
474+
val arguments = ListBuffer[String](
475+
"--release-version", "3.4",
476+
"--add-scram", "SCRAM-SHA-512=[name=alice,password=changeit]",
477+
"--add-scram", "SCRAM-SHA-512=[name=bob,password=changeit]"
478+
)
479+
480+
assertEquals(
481+
"SCRAM is only supported in metadata.version 3.5-IV2 or later.",
482+
assertThrows(classOf[FormatterException], () => runFormatCommand(stream, properties, arguments.toSeq)).getMessage)
483+
}
484+
}

0 commit comments

Comments
 (0)